• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
May 27, 2018 May 27, 2018

Copy link to clipboard

Copied

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.

TOPICS
Acrobat SDK and JavaScript

Views

1.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 28, 2018 May 28, 2018

Check the field calculation order.

Votes

Translate

Translate
Community Expert ,
May 27, 2018 May 27, 2018

Copy link to clipboard

Copied

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;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 27, 2018 May 27, 2018

Copy link to clipboard

Copied

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 27, 2018 May 27, 2018

Copy link to clipboard

Copied

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

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 27, 2018 May 27, 2018

Copy link to clipboard

Copied

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

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 27, 2018 May 27, 2018

Copy link to clipboard

Copied

"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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 27, 2018 May 27, 2018

Copy link to clipboard

Copied

Ok here is the code that finally worked.  With a combination of you all and a friend of mine I was able to get it to work.  Thank you all so much. I definitely needed all the info on here else I wouldn't have had the complete missing links to the puzzle

if (this.getField("BODY").value == 0) {

} else {

var cc = ( this.getField("CHEST").value + this.getField("BICEP").value + this.getField("TRICEP").value + this.getField("SUBSCAPULAR").value + this.getField("MIDAXILLARY").value + this.getField("SUPRAILLIAC").value + this.getField("ABDOMINAL").value + this.getField("THIGH").value + this.getField("MEDIALCALF").value );

var dd = cc*27/this.getField("BODY").value/100;

event.value = dd;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 28, 2018 May 28, 2018

Copy link to clipboard

Copied

You have changed the names of the fields.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 28, 2018 May 28, 2018

Copy link to clipboard

Copied

I used Column 1 vs Column 5

Very first post I noticed I pasted same 3 variables 3 timed, but ee moved on from it so I left it

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 28, 2018 May 28, 2018

Copy link to clipboard

Copied

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  

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 28, 2018 May 28, 2018

Copy link to clipboard

Copied

Check the field calculation order.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 28, 2018 May 28, 2018

Copy link to clipboard

Copied

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​!!!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 28, 2018 May 28, 2018

Copy link to clipboard

Copied

I also needed to add this line of code together with the calculation order:

if (this.getField("BODY").value == 0) {

  // THIS IS NEW ######################

  event.value = 0;

  // #################################

} else {

var cc = ( this.getField("CHEST").value + this.getField("BICEP").value + this.getField("TRICEP").value + this.getField("SUBSCAPULAR").value + this.getField("MIDAXILLARY").value + this.getField("SUPRAILLIAC").value + this.getField("ABDOMINAL").value + this.getField("THIGH").value + this.getField("MEDIALCALF").value );

var dd = cc*27/this.getField("BODY").value/100;

event.value = dd;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 28, 2018 May 28, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 28, 2018 May 28, 2018

Copy link to clipboard

Copied

LATEST

Works perfectly now everyone!  Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines