Skip to main content
Participating Frequently
May 27, 2018
Answered

Should I use Simplified field Notation or Custom Calculation Script? I cannot get either to work. Adobe Acrobat XI Mac OS

  • May 27, 2018
  • 5 replies
  • 1603 views

I simply have 9 columns trying to calculate 9 site body fat in a .pdf form. I chose column 5 randomly for this example that is not working.  I have no preference over option 1, or option 2.  I just need the form to work. Thanks in advance!


OPTION 1: When I try Simplified Field Notation it does the calculation properly buuuuut when I clear the field I get the following error: The value entered does not match the format of the field [s9s4]

(((CHESTTTT+BICEPPPP+TRICEPPPP+SUBSCAPULARRRR+MIDAXILLARYYYY+SUPRAILLIACCCC+ABDOMINALLLL+THIGHHHH+MEDIALCALFFFF)*27))/(BODYYYY)/100

OPTION 2: When I try Custom Calculation script I cannot click OK to save the script due to a syntax error that I cannot find: SyntaxError Missing ; before statement

var m=this.getField("CHESTTTTT");

var n=this.getField("BICEPPPPP");

var o=this.getField("TRICEPPPPP");

var p=this.getField("CHESTTTTT");

var q=this.getField("BICEPPPPP");

var r=this.getField("TRICEPPPPP");

var s=this.getField("CHESTTTTT");

var t=this.getField("BICEPPPPP");

var u=this.getField("TRICEPPPPP");

var v=this.getField("s9s5");

var w=this.getField("BODYYYYY");

v.value=(((m.value)+(n.value)+(o.value)+(p.value)+(q.value)+(r.value)+(s.value)+(t.value)+(u.value))*27)/(w.value))/100;

The red portion is where I think my issue is. The field is formatted for % and needs to be.

This topic has been closed for replies.
Correct answer Bernd Alheit

Check the field calculation order.

5 replies

Participating Frequently
May 28, 2018

Works perfectly now everyone!  Thanks!

Participating Frequently
May 28, 2018

Where is that found? I'll Google it if youre unsure off memory. Getting back to iMac in 15 minutes. Thanks so much.

Participating Frequently
May 28, 2018

1 last issue. It seems like my calculated field doesn't clear out if I clear out the values that led to it. Then if do it a 2nd type that value seems to be included in part of next set of inputs making the 2nd solution incorrect  

Bernd Alheit
Community Expert
Bernd AlheitCommunity ExpertCorrect answer
Community Expert
May 28, 2018

Check the field calculation order.

Participating Frequently
May 28, 2018

Got it!!! Thanks That calculation order did the trick.  Now to try and finish out the rest of the field duplicating this column!  Man I wouldn't have been able to do this without you all @Bernd, gkaiseril, and George_Johnson​!!!!

Inspiring
May 27, 2018

You do have an extra right parentheses in that script. In addition to what Bernd suggested in order to avoid a divide by zero error, you should convert each field value to a number. Otherwise, if any of the fields are blank, it will interfere with the summation of the field values. When you use the value field property to get the field value of a blank field, the result will be a zero length string. If you then add a zero length string to one or more numbers, the result will be a string that is a concatenation of the string representations of the numbers. As an example, if you have four fields that have values of: blank, "1", "2", and "3"

the result of adding their values will be the string "123", not the number 6. So do something like this:

// Get the value of the input fields, as numbers

var n1 = +getField("Text1").value;

var n2 = +getField("Text2").value;

var n3 = +getField("Text3").value;

// Calculate the sum

var sum = n1 + n2 + n3;

// Set this field value

event.value = sum;

The unary + operator used in the first part explicitly converts the field values to numbers, so a blank field value will be converted to zero.

Also, note that to set the value of the field to which the script is attached, the script needs to set event.value to the calculated value as the script above demonstrates. So your script could be revised to:

var m = +getField("CHESTTTTT").value;

var n = +getField("BICEPPPPP").value;

var o = +getField("TRICEPPPPP").value;

var p = +getField("SUBSCAPULARRRRR").value;

var q = +getField("MIDAXILLARYYYYY").value;

var r = +getField("SUPRAILLIACCCCC").value;

var s = +getField("ABDOMINALLLLL").value;

var t = +getField("THIGHHHHH").value;

var u = +getField("MEDIALCALFFFFF").value;

var w = +getField("BODYYYYY").value;

if (w !== 0) {

    event.value = (m + n + o + p + q + r + s + t + u) / w / 100;

} else {

    event.value = "";  // or set to 0 if that's what you want

}

Participating Frequently
May 28, 2018

Im thinking the red part is wrong...it's not calculating at all now. Was I supposed to name "event" as the name of the cell it goes in?  I named the cell "s9s5" also which did not work. Field just shows 0.00% and continues to give me the error

// Get the value of the input fields, as numbers

var m=this.getField("CHESTTTTT");

var n=this.getField("BICEPPPPP");

var o=this.getField("TRICEPPPPP");

var p=this.getField("SUBSCAPULARRRRR");

var q=this.getField("MIDAXILLARYYYYY");

var r=this.getField("SUPRAILLIACCCCC");

var s=this.getField("ABDOMINALLLLL");

var t=this.getField("THIGHHHHH");

var u=this.getField("MEDIALCALFFFFF");

var w=this.getField("BODYYYYY");

// calculate sum

var sum=m+n+o+p+q+r+s+t+u;

//set this field value

event.value=sum;

if (w !== 0) {

    event.value = (m+n+o+p+q+r+s+t+u)*27 / w / 100;

} else {

    event.value = "";  // or set to BLANK

}

Inspiring
May 28, 2018

"event" is the object (field) that currently is being processed. If you were to use "getField" to access that object you would get the properties of that field before you ran your script.

Bernd Alheit
Community Expert
Community Expert
May 27, 2018

Try this:

if (w.value != 0)

v.value=(m.value+n.value+o.value+p.value+q.value+r.value+s.value+t.value+u.value)*27/w.value/100;

else

v.value = 0;

Participating Frequently
May 27, 2018

var m=this.getField("CHESTTTTT");

var n=this.getField("BICEPPPPP");

var o=this.getField("TRICEPPPPP");

var p=this.getField("SUBSCAPULARRRRR");

var q=this.getField("MIDAXILLARYYYYY");

var r=this.getField("SUPRAILLIACCCCC");

var s=this.getField("ABDOMINALLLLL");

var t=this.getField("THIGHHHHH");

var u=this.getField("MEDIALCALFFFFF");

var v=this.getField("s9s5");

var w=this.getField("BODYYYYY");

if (w.value != 0)

v.value=((m.value+n.value+o.value+p.value+q.value+r.value+s.value+t.value+u.value)*27)/((w.value)/100);

else

v.value = 0;

Progress!!!! But one issue now is it is not calculating properly.  I think we'd need to maybe add another variable then somehow make it simpler ...

like (v.value/z.value)/100 IF im understanding this thing correctly.