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

Fix calculation error after form has been submitted

Community Beginner ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

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?

TOPICS
How to , JavaScript , PDF forms

Views

2.6K

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 , Jun 08, 2021 Jun 08, 2021

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\").valu
...

Votes

Translate

Translate
Community Expert ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

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?

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 Beginner ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

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

 

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 ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

What's the name of this field?

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 Beginner ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

Total points allocated for Functionality 

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 ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

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

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 Beginner ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

Thank you very much, there are 2 ")" missing in your code though, but works 100%

Here are the corrected lines for future referance 

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

 

Thanks again!

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 ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

Sorry, I wrote it "blindly". Fixed it now...

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 Beginner ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

No Problem, I know asking a different question on this thread might get me yelled at, but while you are there, is it possible to rename the files using 2 of the field in the form. They all have the same name and I need to send the corrected forms back to the senders.

Using the same process as above could one save all the forms in a folder with filename (Fields) = Bid Number + Evaluator Name?

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 ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

Yelled at? Not at all!

 

Sure, that's possible. Do you want to save them in the same folder as they were originally, or another one?

They won't be renamed, though. A new copy will be saved under the new name, but the old one will still exist.

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 Beginner ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

New folder will be easier

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 ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

Well, you will have to create that folder in advance, as the script can't do it for you.

Let's say you use "C:\Files\".

Create an Action that executes the following code, and then run it on your files:

this.saveAs("/C/Files/" + this.getField("Bid Number").valueAsString + " " + this.getField("Evaluator Name").valueAsString + ".pdf");

 

(I assumed you wanted a space between the number and the name...)

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 Beginner ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

It saves them with the same name. Checked the field names are correct 

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 Beginner ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

it might have to do with duplicate files. Seems when it finds one it just saves the original name and the does not continue to run the 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
Community Expert ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

Not sure what you mean... If you have the same values in those fields under multiple files then the new files will just overwrite one another in the target folder, as they will have the same file-name.

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 Beginner ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

I think it runs out of memory. did only 600 of the 1400, but tyring to run in batches now

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 ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

That's quite possible. Acrobat has a very bad memory handling system and can get stuck when trying to process too many files (partially because it insists on loading each file visually, which makes it very slow and consumes a lot of memory), so doing it in batches is a good idea.

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 Beginner ,
Jun 24, 2021 Jun 24, 2021

Copy link to clipboard

Copied

Hi, Could you help me again with this please. At the moment it replaces any files that are duplicate and depanding on how the files are save it might replace an older version. Is it possible to add a prefix to the file name when it finds duplicates?  

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 Beginner ,
Jun 24, 2021 Jun 24, 2021

Copy link to clipboard

Copied

I guess ment a suffix 

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 Beginner ,
Jun 24, 2021 Jun 24, 2021

Copy link to clipboard

Copied

meant....

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 ,
Jun 24, 2021 Jun 24, 2021

Copy link to clipboard

Copied

You can add a prefix/suffix to the file name by default, but doing so when the target file already exists is more complicated. Another option is to set the saveAs method to prompt you in such a situation.

To do that add the following parameter to it:

bPromptToOverwrite: true

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 Beginner ,
Feb 21, 2022 Feb 21, 2022

Copy link to clipboard

Copied

Hi. Me agian. Could you please just help me again please.

 

I have 4 scripts that I run to fix a template. The templated changed on day 2 of this process but people still used the old one. Now I need to fix about 6000 forms. 

1. I export the FDF.

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

2. Then I Import it back into the new template, this I need to select and do one by one.

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

3. Then I make some changes, one of the fields default value is imported as part of the FDF and that needs to change

var newCalcCode = "\
event.value= 35;";
this.getField("A2").setAction("Calculate", newCalcCode);
this.getField("BID NUMBER").value = this.getField("Bid Number").value;
this.calculateNow();

4. Then i recalculate everyting - Not sure this is neccesary

this.calculateNow();

 and the the form is saved that i have to select again as it wants to ovewrite the new tempate i have selected and the names will then all be the same

 

How do I do get past doing them one by one? The other script you helped with works 100%, i just select all of them and it runs, but this one where the form changes I cant figure out. MAybe i should mention that the incorrect form has an extra field that the new tempate does not, so besides just the code that needs updateding it alos look diffrent, hence why I select the new form in the process. 

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 ,
Feb 21, 2022 Feb 21, 2022

Copy link to clipboard

Copied

Just create an Action that has an Execute JavaScript command with this code, followed by a Save command, and then run it on your files.

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 Beginner ,
Feb 21, 2022 Feb 21, 2022

Copy link to clipboard

Copied

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. 

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 ,
Feb 21, 2022 Feb 21, 2022

Copy link to clipboard

Copied

LATEST

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

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