Javascript doesnt run from Button action

New Here ,
Oct 09, 2019

Copy link to clipboard

Copied

Hi everybody,

 

I have the feeling my problem should be simple to solve but I cant figure it out. I am very new to this .. so I might be absolutley on the wrong track.

 

I have two PDF forms: A0.pdf and A1.pdf. The user should fill the template A0.pdf and if required afterwards also the additional template A1.pdf. As there are form fields containing the same information in both forms, I would like to transfer the mutual data from the A0.pdf to the A1.pdf . My idea was to use a button in the A0.pdf that if pressed opens an empty template of the A1.pdf and then fills in the data. Here is what I came up with so far as an example for one Name field:

 

 

var v = this.getField("A0-Name1");
var myDoc = app.openDoc({cPath: "/C/UserData/user/Documents/A1-template.pdf", bHidden: false});
myDoc.getField("A1-Name1").value = v.value;

 

 

The script works when I run it from the console. But when I trigger it trough the action of my button the following error is returned:

 

 

TypeError: myDoc is undefined
3:AcroForm:A1button:Annot1:MouseUp:Action1

 

 

can anyone help or has a different solution to my problem?

 

Thank you very much 🙂

 

Tullius

Adobe Community Professional
Correct answer by Bernd Alheit | Adobe Community Professional

Set the property disclosed of the document.

TOPICS
Acrobat SDK and JavaScript, How to, PDF forms

Views

146

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

Javascript doesnt run from Button action

New Here ,
Oct 09, 2019

Copy link to clipboard

Copied

Hi everybody,

 

I have the feeling my problem should be simple to solve but I cant figure it out. I am very new to this .. so I might be absolutley on the wrong track.

 

I have two PDF forms: A0.pdf and A1.pdf. The user should fill the template A0.pdf and if required afterwards also the additional template A1.pdf. As there are form fields containing the same information in both forms, I would like to transfer the mutual data from the A0.pdf to the A1.pdf . My idea was to use a button in the A0.pdf that if pressed opens an empty template of the A1.pdf and then fills in the data. Here is what I came up with so far as an example for one Name field:

 

 

var v = this.getField("A0-Name1");
var myDoc = app.openDoc({cPath: "/C/UserData/user/Documents/A1-template.pdf", bHidden: false});
myDoc.getField("A1-Name1").value = v.value;

 

 

The script works when I run it from the console. But when I trigger it trough the action of my button the following error is returned:

 

 

TypeError: myDoc is undefined
3:AcroForm:A1button:Annot1:MouseUp:Action1

 

 

can anyone help or has a different solution to my problem?

 

Thank you very much 🙂

 

Tullius

Adobe Community Professional
Correct answer by Bernd Alheit | Adobe Community Professional

Set the property disclosed of the document.

TOPICS
Acrobat SDK and JavaScript, How to, PDF forms

Views

147

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
Oct 09, 2019 0
Adobe Community Professional ,
Oct 13, 2019

Copy link to clipboard

Copied

Hi,

 

Is that supposed to be a document level script?

 

Where are you placing the code?

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
Reply
Loading...
Oct 13, 2019 0
Adobe Community Professional ,
Oct 13, 2019

Copy link to clipboard

Copied

Set the property disclosed of the document.

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
Reply
Loading...
Oct 13, 2019 0
Tullius1 LATEST
New Here ,
Oct 13, 2019

Copy link to clipboard

Copied

That was the solution! thank you very much 🙂

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
Reply
Loading...
Oct 13, 2019 0