Copy link to clipboard
Copied
Hello helpful people!
I need to create a script for a button that will export certain field data from PDF Form 1 to the exactly named fields on PDF Form 2. It needs to be a button as overly complicated instructions go over like lead balloons. Thanks all!
Copy link to clipboard
Copied
The easiest way to do that is to save the date to a global variable when exporting, and then copy it back to the field with the same name when importing.
The basic code can be something like this:
// Export script
if (global.myData==null) global.myData = {};
global.myData["Text1"] = this.getField("Text1").valueAsString;
// Import script
if (global.myData==null) app.alert("No global data was found.");
else this.getField("Text1").value = global.myData["Text1"];
Copy link to clipboard
Copied
@try67 Thank you.
I input the following code on a button in Form 1:
// Export script
if (global.myData==null) global.myData = {};
global.myData["CrtAuditPeriod"] = this.getField("CrtAuditPeriod").valueAsString;
And the below code on a button in Form 2:
// Import script
if (global.myData==null) app.alert("No global data was found.");
else this.getField("CrtAuditPeriod").value = global.myData["CrtAuditPeriod"];
Unfortunately it did not work. Any more tips?
Copy link to clipboard
Copied
No, you need to better explain what "did not work" means, exactly. Did it copy something at all? If not, was there an error message? If so, what did it say? etc.
Copy link to clipboard
Copied
I mean, nothing happened. I clicked on the first button, went to the second form and clicked on the second button. Nothing happened. No error messages, no information copied over. Literally nothing happened.
Copy link to clipboard
Copied
Check the JS Console (Ctrl+J) for error messages.
Copy link to clipboard
Copied
@try67 Form 1 has this error:
NotAllowedError: Security settings prevent access to this property or method.
Global.myData:2:Field Import:Mouse Up
Form 2 gets this error:
NotAllowedError: Security settings prevent access to this property or method.
Global.myData:2:AcroForm:Import:Annot1:MouseUp:Action1
I did check security under properties and there is no security selected.
Copy link to clipboard
Copied
OK, now we're getting somewhere. Go to Edit - Preferences - JavaScript and tick off the box next to "Enable global object security policy", then try it again.
Copy link to clipboard
Copied
@try67 Yea! That worked. Unfortunately, when I try to add more lines I get a syntax error on Form 2, no error on Form 1:
Copy link to clipboard
Copied
You can't have two else clauses after a single if statement. Use if-else if-else if...-else.
Copy link to clipboard
Copied
@try67 Now I have this:
Copy link to clipboard
Copied
There is nothing between if and else
Copy link to clipboard
Copied
@Bernd Alheit Can you be more specific? I am a complete and utter novice. What should go between?
Copy link to clipboard
Copied
( ) with a condition.
Copy link to clipboard
Copied
Also, if else must come after if, not after the final else.
I recommend you spend some time studying the core JS syntax.
Copy link to clipboard
Copied
Hi @Leah31805381ekx5
Hope you are doing well and thanks for reaching out.
The workflow you are trying to achieve is might be possible using JavaScript. For more information please check the help pages listed below:
https://acrobatusers.com/tutorials/javascript_console/
https://helpx.adobe.com/acrobat/using/applying-actions-scripts-pdfs.html
Hope it will help
Regards
Amal
Copy link to clipboard
Copied
@Amal. I am not a coder therefore neither of those help very much. They are like reading a foreign language.
Copy link to clipboard
Copied
The easiest way is to use data export/import.
Copy link to clipboard
Copied
You can install it in the quick toolbar.