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

Button to export fields from forms PDF1 to PDF2

Explorer ,
Nov 02, 2023 Nov 02, 2023

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!

TOPICS
Create PDFs , JavaScript , PDF , PDF forms

Views

1.4K

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

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

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

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?

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

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.

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

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.

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

Copy link to clipboard

Copied

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

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

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.

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

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.

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

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:

Screenshot 2023-11-03 091422.jpg

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

There is nothing between if and else 

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

( ) with a condition. 

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

Copy link to clipboard

Copied

LATEST

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

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

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

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

The easiest way is to use data export/import.

 

Capture_2311031026.png

 

 

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

Copy link to clipboard

Copied

You can install it in the quick toolbar.

 

Capture_2311031028.png

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