Copy link to clipboard
Copied
I have a list of pdf documents, all of them have "ABC" field which is a sum of fields Field1 and Field2. I need to change the rule and add one more filed to the sum.
I use Tools>Action Wizard and JavaScript like this:
var f = this.getField("ABC");
f.setAction('Calculate', "AFSimple_Calculate(\"SUM\", \"Field1, Field2, Field3\");" );
But after applying the action to the docs nothing was changed. What am I doing wrong?
Thanks!
1 Correct answer
This code works as expected for me:
var f = this.getField("ABC");
f.setAction("Calculate", "AFSimple_Calculate(\"SUM\", new Array(\"Field1\", \"Field2\", \"Field3\"));");
Copy link to clipboard
Copied
Did you add a Save step?
Copy link to clipboard
Copied
Sure, I did. For instance, this code works OK
var f = this.getField("GELEOtherClothing");
f.value = 100;
Copy link to clipboard
Copied
It seems to apply the script, but it's not reflected in the calculate tab of the field properties dialog as you would expect. Is the calculation being performed correctly for you?
Copy link to clipboard
Copied
The fields are blank, they are to be populated by users. I added some test values and the calculation performed correctly. But this is not what I need. I need to change the filed properties. Our designer made a mistake, he missed some fileds to be sum up. More that 50 copies of the document was created and all of them have the same issue of course. I would like to write a script to fix all the documents using Tools>Action Wizard instead of fixing each document manually. Is it possible?
Copy link to clipboard
Copied
This code works as expected for me:
var f = this.getField("ABC");
f.setAction("Calculate", "AFSimple_Calculate(\"SUM\", new Array(\"Field1\", \"Field2\", \"Field3\"));");
Copy link to clipboard
Copied
Thanks! George_Johnson code works OK!
Copy link to clipboard
Copied
In addition to adding a Save step, add this line to the end of your code:
this.calculateNow();
Copy link to clipboard
Copied
Thanks for your answer, but with this.calculateNow(); the result is the same, nothing was changed in the docs.
May be I wasnt clear. I dont need the field to be re-calculated on doing JavaScript, I need to change field's property, the list of fields to be sum up. Am I on the right way?
Copy link to clipboard
Copied
You do need to perform a re-calculation, because just setting a new action to the field's Calculation event does not actually trigger it.

