Skip to main content
Known Participant
June 8, 2021
Answered

Fix calculation error after form has been submitted

  • June 8, 2021
  • 1 reply
  • 4500 views

Hi
I have a form that was distributed and returned. 3000 of them. I found a calculation error on one of the fields and need to rectify this before sending in the forms. I can export an individual form to an fdf file and import it into the new corrected format, but to do this for 3000 form will not be possible. Is there a way to do this in bulk?

This topic has been closed for replies.
Correct answer try67

Total points allocated for Functionality 


OK, you need to create two Actions, then. One to export the form data to an FDF file, and one to fix the code and then import it back in.
This is the code to use for the first Action:

 

 

this.exportAsFDF({bAllFields: true, cPath: this.path.replace(/\.pdf$/i, ".fdf")});

 

 

This is the code for the second Action:

 

 

var newCalcCode = "\
var v1 = AFMakeNumber(getField(\"Total A1\").value);\n\
var v2 = AFMakeNumber(getField(\"Total A2\").value);\n\
var v3 = AFMakeNumber(getField(\"Total A3\").value);\n\
var v4 = AFMakeNumber(getField(\"Total B1\").value);\n\
var v5 = AFMakeNumber(getField(\"Total B2\").value);\n\
var v6 = AFMakeNumber(getField(\"Total B3\").value);\n\
event.value= (v1+v2+v3+v4+v5+v6);";
this.getField("Total points allocated for Functionality").setAction("Calculate", newCalcCode);
this.importAnFDF({cPath: this.path.replace(/\.pdf$/i, ".fdf")});
this.calculateNow();

 

 

You also need to add a Save command to this Action, after executing the code.

Now run the first Action on all of your original files, then the second one. That part might be a bit tricky as Acrobat attempts to process all non-PDF files, unfortunately, so you might have to select them manually, instead of just selecting the entire folder (since it will also contain the new FDF files we created in the previous Action).

 

Edit: code fixed

1 reply

try67
Community Expert
Community Expert
June 8, 2021

Do you have Acrobat Pro? What does fixing the calculation error involve? Did you use a script for the calculation, or one of the other built-in options?

Known Participant
June 8, 2021

Yes I have pro.

The field sums A1 to b3 then multiplies by 0.75. This multiplication is wrong and must be removed

The formula should just sum the fields

var v1 = AFMakeNumber(getField("Total A1").value)
var v2 = AFMakeNumber(getField("Total A2").value)
var v3 = AFMakeNumber(getField("Total A3").value)
var v4 = AFMakeNumber(getField("Total B1").value)
var v5 = AFMakeNumber(getField("Total B2").value)
var v6 = AFMakeNumber(getField("Total B3").value)

event.value= (v1+v2+v3+v4+v5+v6)*0.75

 

try67
Community Expert
Community Expert
February 21, 2022

it is in an action. Porblem is it needs to import into a diffrent file. The other script used the same file and corrected the formulas, this one you need to specify 2 files, the fdf and where it needs to bring that data in as the template differs. 


Opening another PDF file in an Action is tricky. If you want to do it then you have to manually close it, while keeping the original open, as well as keep a separate variable pointing to it and to the old document, instead of using "this".