Expand my Community achievements bar.

Average Calculation Possible In LiveCycle?

Avatar

Level 2

Hello Adobe Fam,

I am new to LiveCycle and was wondering if average calcuation works in LiveiCycle at all?  I have a form that I built in Adobe Acrobat that works 100% and calculates dropdowns with no problem.  Manager is now requesting to allow comment boxes to expand as more text is added which i can't figure out in Adobe Acrobat but able to do in LiveCycle with no issue, but the actual average calculation is not workinag at all for the 8 dropdowns now but works 100% in Adobe Acrobat??  One thing this code does is excludes N/A from being counted in calcuation if selected.

Below is script that came over from the working PDF I built:

// Average non-N/A values;

var aFieldNames = new Array("Dropdown1", "Dropdown2","Dropdown3","Dropdown4","Dropdown5","Dropdown6","Dropdown7","Dropdown8");

// counter for non-N/A values;

var nCount = 0;

// variable to sum non-N/A values;

var nSum = 0;

// default value for result if no average computed;

event.value = 0;

// process array of field names;

for(i = 0; i < aFieldNames.length; i++) {

if(this.getField(aFieldNames[i]).valueAsString != "N/A") {

// field does not have a value of "N/A";

nCount++; // increment counter

nSum += Number(this.getField(aFieldNames[i]).value); // add value to sum

} // end value not N/A;

} // end loop processing one field;

// compute the average;

if(nCount != 0) {

// non-zero divisor so we can compute the average;

event.value = nSum / nCount;

}

Thanks N advance for any help

7 Replies

Avatar

Level 1

I have the exact same issue. I had to read it twice to make sure I hadn't written it.  I need to have a value for each text selected, then average them then have a text attached to the average (overall score). Will someone please look at this again and assist? Thank you!!!

Avatar

Level 1

I would like to know the same thing. Has anybody contacted you.  I can get my fields to calculate and average correctly, I just cannot figure out how to get it to ignore the N/A picked fields in the average.  HELP

Avatar

Level 2

I actually had to go the route of totally removing N/A and keeping the space blank.  So if users want to select N/A, they just have to select the empty space which represents n/a and is also not counted in my final total/average

Avatar

Level 1

Sound like a reasonable solution.

Avatar

Level 7

Here's my solution:

I had to set the binding for the dropdowns to numbers. I didn't know what numbers you were using, so I picked "0" for what "N/A" would get, but you can pick whatever. For the form, I made one dropdown and then copy/pasted it however many times I wanted. (In this case 8 to match your example.) I put the code in the calculate event for the text field I was using to report the average.

var n = 0;

var total = 0;

for (var i=0; i<8; i++){

          if (!xfa.resolveNode("dd1["+i+"]").isNull && xfa.resolveNode("dd1["+i+"]").rawValue != 0){

                    n++;

                    total += Number(xfa.resolveNode("dd1["+i+"]").rawValue);

          }

}

this.rawValue = total/n;

Avatar

Level 1

jasotastic81

I'm getting close with your scripting, this is what I need my drop down has 9 total entries and calculates only 2 drop boxes fields giving the grade in the total box for the two days.

100

95

85

75

60

40

20

0

N/A

I want the 0 to calculate as 0 so that if they get 100 one day and 0 the next the average is 50.  and the N/A if picked then it just puts what they got for the 1st day so n/a and 100 returns 100.  if both are NA then it it should show NA.  Any help would be appreciated.

Dakotajessie

Avatar

Level 7

Alright, then after you've copy/pasted the drop downs, set the data binding values to match the numbers, then use "-1" for N/A. Change the if statement to the following:

if(!xfa.resolveNode("dd1[+i+"]").isNull && xfa.resolveNode("dd1["+i+"]").rawValue >= 0){

*Note: This could probably be streamlined a little since you only have 2 drop downs, but this will work and allow for later expansion if you add more drop downs later.