Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

How can I count only text fields that have been used?

Avatar

Level 2

Hi,

I'm using Livecycle Designer for a dynamic form.  I have a section of the form that contains field for the user to enter goals and then rate the goal.  I'd like to count only the text fields with entries and then have the total number of rates divided by the number of text field entries.

Row 1 , column 1 -- Goal is to pick up 5 apples.   Row 1, column 2 - the rate given is 5

Row 2, column 1 - Goal is to pick up 5 pears.  Row 1, column 2 - the rate given is 5

Two goals for a total rating of 10     ---  10 divided by 2 = 5

Is it possible to count only those fields that are populated?

Also, is it possible to create an error message if the user entered 5 goals but only rated 4 of them?

1 Accepted Solution

Avatar

Correct answer by
Level 7

Please send me the form at

allendavid@co.kane.il.us. I'll get it fixed up for you and send it back and then you'll have the code as a sample for future reference.

View solution in original post

23 Replies

Avatar

Former Community Member

I am not certain if I have exactly what you are looking for but the attached encapsulates all of the functionality you requested in a table format.

Untitled.png

Steve

Avatar

Level 2

Hi Steve,

I've set up the table you have below.  I need to know how to count the number of goals (text fields) and then divide it by the sum total of the rates given.  This would be more of a grading table.  The rate is actually a point given for successful completion.  So if I have 3 goals with a sum rate total of 15, my overall average score would be 5. (15/3=5)

The reason for the error message is that sometimes end users give an empty goal field a rate --- without populating the goal fields.  Ex.  3 goals entered with 4 rates entered - each at 5 points.  Now there is a total of 20 points changing the average score to 6.66.   (20/3=6.66).

I hope that's a better description.  Very much appreciate your help with this.

Kathleen

Avatar

Level 7

You could do a simple check for null and increase a counting variable if there's a value in the field. Here's a sample:

var goalCount = 0;

if (field1.rawValue != null){

     goalCount = goalCount + 1;

}

if (field2.rawValue != null){

     goalCount = goalCount + 1;

}

if (field3.rawValue... etc.

this.rawValue = totalPoints/goalCount;

where totalPoints is a sum of the values in the goal fields. This script is javascript and should be placed in the calculate event of the field showing your average score.

Avatar

Level 2

Hi,

Your answer is a big help with another area I'm having trouble with...thank you!.  However, I'm not sure its working for the image below.  I'm hoping to be able to remove the word "enter" if there is a way to count the populated text fields (i.e., #10, #11, etc).  Each field has the title of Duty1, Duty2,....  I'd like to leave the calc for totaling the points so that the end user can see total points and if possible, total number of duties.  It would be easier just to have them enter the number of duties themselves, but we've had too many using the wrong number and as such getting the wrong score.

I also failed to add that I'm a beginner in Adobe...just starting to become familiar with calc's and scripting.  Sorry for the confusion.

adobe officer calc help.jpg

Kathleen

Avatar

Level 7

Again, you'd be doing a check for null, i.e.:

var dutyCount = 0;

if (Duty1.rawValue != null){

     dutyCount = dutyCount + 1;

}

if (Duty2.rawValue... etc.

this.rawValue = dutyCount;

This script would go on the calculate event of the "Enter Total Number of Essential Duties and Responsibilites". It'll display the number of non-blank Duty fields. The

!= symbol means not equal to in javascript.

Avatar

Level 2

I'm sorry to be such a pain.  I've been working on basic stuff and this is far out of my depth.  I am reading through one of the Adobe LiveDesigner books but at a loss.  This is what I have so far.  There are two that already have a duty listed so those two cells are in ready only.   I changed the 0 to 2 and it did count those to entries, however, when the others were populated it didn't count them.  

VAR TOTALESSENTIALDUTIES

VAR TOTALESSENTIALDUTIES=0;IF(ESSENTIALDUTY1.RAWVALUE!=NULL){TOTALESSENTIALDUTIES=TOTALESSENTIALDUTIES+1;}IF(ESSENTIALDUTY2.RAWVALUE!=NULL){TOTALESSENTIALDUTIES=TOTALESSENTIALDUTIES+1;}IF(ESSENTIALDUTY3.RAWVALUE!=NULL){TOTALESSENTIALDUTIES=TOTALESSENTIALDUTIES+1}THIS.RAWVALUE=TOTALESSENTIALDUTIES;

Avatar

Correct answer by
Level 7

Please send me the form at

allendavid@co.kane.il.us. I'll get it fixed up for you and send it back and then you'll have the code as a sample for future reference.

Avatar

Level 2

Hi David,

Something strange happened with the file I sent you. Not sure how I managed to removed the updates I made despite saving them at each change. Ugh.

This file has a bunch of flaws the at least it has the field I need help with. Sorry for the mess.

Avatar

Level 7

It's not a problem, I added the fields that were missing and sent the form back to you. The totals and averages now work and I put a couple of examples of checking to see whether or not previous fields had been filled in. Hope it helps.

djaknow

Avatar

Level 2

It's beautiful!!

I tried to copy the script into the "fixed" file. Not sure if I'm doing it right. Does do what it's supposed to do but also gives an error message.

If I copy and paste the script into Calculation? Is that correct?

I tried to unsuccessfully delete it.

Avatar

Level 2

This error message will not let me past rating three.  If I go from the 12th goal up to 3 it works fine.

error script pads.jpg

Avatar

Level 7

That's not one of the scripts I added so I'm not sure where it is on your form, but I see that it's calling out a division by zero so there must be something wrong with your TOTALESSENTIALduties field or variable. Whatever TOTALESSENTIALduties is, it should have a 2 in it right from the start because you have 2 duties filled in by default.

Avatar

Level 2

That was one of my bad attempts and figuring this out.   

here's the error the message that's stopping the progress to number 4

error two.jpg

Avatar

Level 7

Hi Kat,

I've made a change to the form I sent you yesterday and emailed it to you, the error is taken care of.

Avatar

Level 2

Hi, even before the error could be fixed, it got good reviews from management.  I was about to see if I could copy your adjustment to the one I was working on when management decided to change things up again.  Another late night and more gray hair, its close to being finished.  They changed another section to have a grading scale like the first one.  I tried to mimic what you had in the scripting and as expected, can't get it right.  I'll email the revised file to you again in hopes that you would be willing to help correct the new section's calc script and with the error.   If you can't I understand.

Avatar

Level 7

Sure, I'll take a look and see what I can do. If I have questions I'll shoot you an email.

Avatar

Level 7

Hi Kathleen,

I think this form may be corrupted. The sums in the table are giving me problems no matter what I do. Most of the issues you were getting errors on were simple case mismatches (i.e. - goalcount instead of goalCount) but something definitely appears wrong with the table. Has this form been worked on by one person or has it been passed among several people? Just wondering, if several people have worked on it, if everyone's on the same version of Designer?

Dave Allen

IS Tech

Kane County Circuit Clerk

630.208.2151

Avatar

Level 2

Its only been worked on by me.  I think its the first one you helped me with that I worked through to match what the final product was which would be the file you have now.  I'm using Adobe Livecycle Designer ES, verison 8.2.1.3144.4.471865.  When its sent out to multiple end users, I figured I would have to save it in a lower version of Adobe to make sure all would be able to open it.

Avatar

Level 7

Ok, I'll have a look at it tonight at home when I have more free time. I'm not sure what could be causing the problem with the calculation in the table so it may take a bit of time to go through everything. Will it be a problem if I make changes in the hierarchy? The form will look exactly the same, it's just a little cluttered (please don't take offense, compared to my rookie forms it's actually quite good) in the hierarchy.

One thing about saving the form to a lower version, you don't want to go any lower than 7.0.5 or some of the functionality could be lost.

Regards,

Dave Allen

IS Tech

Kane County Circuit Clerk

630.208.2151