Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


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

1.3K

Likes

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

Adobe Community Professional , 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\").val...

Likes

Translate

Translate
Adobe Community Professional ,
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?

Likes

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

 

Likes

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

Copy link to clipboard

Copied

What's the name of this field?

Likes

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 

Likes

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
Adobe Community Professional ,
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

Likes

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!

Likes

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

Copy link to clipboard

Copied

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

Likes

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?

Likes

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
Adobe Community Professional ,
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.

Likes

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

Likes

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
Adobe Community Professional ,
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...)

Likes

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 

Likes

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

 

Likes

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
Adobe Community Professional ,
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.

Likes

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

Likes

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
Adobe Community Professional ,
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.

Likes

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?  

Likes

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 

Likes

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

Likes

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

Copy link to clipboard

Copied

LATEST

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

Likes

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