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

Button to export fields from forms PDF1 to PDF2

Explorer ,
Nov 02, 2023 Nov 02, 2023

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!

TOPICS
Create PDFs , JavaScript , PDF , PDF forms
2.1K
Translate
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 ,
Nov 02, 2023 Nov 02, 2023

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"];

Translate
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 ,
Nov 02, 2023 Nov 02, 2023

@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?

Translate
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 ,
Nov 02, 2023 Nov 02, 2023

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.

Translate
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 ,
Nov 02, 2023 Nov 02, 2023

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.

Translate
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 ,
Nov 02, 2023 Nov 02, 2023

Check the JS Console (Ctrl+J) for error messages.

Translate
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 ,
Nov 03, 2023 Nov 03, 2023

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

Translate
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 ,
Nov 03, 2023 Nov 03, 2023

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.

Translate
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 ,
Nov 03, 2023 Nov 03, 2023

@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:

Screenshot 2023-11-03 091422.jpgexpand image

Translate
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 ,
Nov 03, 2023 Nov 03, 2023

You can't have two else clauses after a single if statement. Use if-else if-else if...-else.

Translate
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 ,
Nov 06, 2023 Nov 06, 2023

@try67 Now I have this:Screenshot 2023-11-06 113652.jpgexpand image

Translate
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 ,
Nov 06, 2023 Nov 06, 2023

There is nothing between if and else 

Translate
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 ,
Nov 06, 2023 Nov 06, 2023

@Bernd Alheit Can you be more specific?  I am a complete and utter novice.  What should go between?

Translate
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 ,
Nov 06, 2023 Nov 06, 2023

( ) with a condition. 

Translate
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 ,
Nov 06, 2023 Nov 06, 2023
LATEST

Also, if else must come after if, not after the final else.

I recommend you spend some time studying the core JS syntax.

Translate
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 Employee ,
Nov 02, 2023 Nov 02, 2023

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

Regards
Amal
Translate
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 ,
Nov 02, 2023 Nov 02, 2023

@Amal. I am not a coder therefore neither of those help very much.  They are like reading a foreign language.

Translate
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 ,
Nov 03, 2023 Nov 03, 2023

The easiest way is to use data export/import.

 

Capture_2311031026.pngexpand image

 

 


Acrobate du PDF, InDesigner et Photoshoptographe
Translate
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 ,
Nov 03, 2023 Nov 03, 2023

You can install it in the quick toolbar.

 

Capture_2311031028.pngexpand image


Acrobate du PDF, InDesigner et Photoshoptographe
Translate
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