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

Acrobat DC - launch javascript on startup

Explorer ,
Dec 05, 2019 Dec 05, 2019

I'm trying to hide a field when another field contains a certain value.
It works when I use it on "prepare form" but the script is not launch on startup.
I tried it with document's javascript and it look like nothing happens.
I'm using Adobe Acrobat DC 2019.0.21.20056.
Thanks for your help.

TOPICS
How to , PDF forms
4.9K
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
1 ACCEPTED SOLUTION
Explorer ,
Dec 13, 2019 Dec 13, 2019

So, according the information you gave me, the solution I applied is :
Add an action to the first field on the document when it's selected.
It launches my javascript code.

In this way, the user just have to click on the first field to apply the script.

Thanks for your help.

View solution in original post

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
LEGEND ,
Dec 05, 2019 Dec 05, 2019

In your document scripts, make sure you do not have it in a function. If in doubt show a screen shot. Also check the console for 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
Explorer ,
Dec 05, 2019 Dec 05, 2019

It's not on a function.

I know the script works, but not before opening the script  editor...

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 ,
Dec 05, 2019 Dec 05, 2019

What script does you use? Where does you use the script?

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
Explorer ,
Dec 05, 2019 Dec 05, 2019

This one :

var test = this.getField("p1_data_ismarie");  

var aEffacer = this.getField("p1_data2_veuf_de");

if(test.value=='X '){
    aEffacer.display = display.hidden;
}
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 ,
Dec 05, 2019 Dec 05, 2019

Where does you use the script?

 

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
Explorer ,
Dec 05, 2019 Dec 05, 2019

On javascript tool (bottom right)>Document scripts(top middle)>modify
The script is launching only if y go there, then I click OK

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 ,
Dec 06, 2019 Dec 06, 2019

Document scripts are executed when the PDF is opened. If you are experiencing an issue, then there is something else interfering with the script. Please post your PDF and we'll look at it.

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
Explorer ,
Dec 06, 2019 Dec 06, 2019

Thanks, you can find both files (data and model) here : https://easyupload.io/1saqdb

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 ,
Dec 06, 2019 Dec 06, 2019

Your script will be executed when you open the document.

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
Explorer ,
Dec 06, 2019 Dec 06, 2019

this is my issue.... it's not working, the field "p1_data_ismarie" contains a value ("X ") but the action is done only when I open the javascript edit then I click ok to close it....

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 ,
Dec 06, 2019 Dec 06, 2019

Fill the field, save and close the document. What happens when you open the saved document?

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
Explorer ,
Dec 08, 2019 Dec 08, 2019

Absolutely nothing before I'm going on the javascript menu (then click edit then ok)

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
LEGEND ,
Dec 06, 2019 Dec 06, 2019

Ah, I see you have an XFDF file. I also see that the PDF is empty, so p1_data_ismarie will never be 'X  '  . You talk about "opening" the file. But are you actually opening the XFDF which opens the PDF?

 

The flow is:

- the PDF is opened

- document open scripts are run

- the XFDF file is imported to change fields

So the document open scripts are not affected by the contents of the XFDF.

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
Explorer ,
Dec 08, 2019 Dec 08, 2019

I'm opening the xfdf file then it asks me to choose the pdf file.
It means that I need that my script waits for the importation before launching the script?
Is it possible? May I do a loop with a setTimeOut?

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
LEGEND ,
Dec 09, 2019 Dec 09, 2019

I don't think you can do what you want to do. Document open will happen before import. The way you trigger the import is not important. Document open MUST happen before import because the import may rely on form field changes made during document open actions. Back to the drawing board, I think. Why not put the final data in the XFDF?

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
Explorer ,
Dec 12, 2019 Dec 12, 2019

Final datas are in the xfdf....
The script modify the behaviour of a field in a certain one (data) has a specific value.

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 ,
Dec 10, 2019 Dec 10, 2019

Why  is the file being opened by the XFDF?  Maybe there is a better way.  Tell us what you are trying to do.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
Explorer ,
Dec 12, 2019 Dec 12, 2019

The user open the xfdf then it's automatically importing it on the pdf file.
I want to erase a text field (data) if an element is checked (data).

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 ,
Dec 12, 2019 Dec 12, 2019

It sounds like you want two incompatible features. Data loaded with the XFDF and data manipulation with scripts. It's not easy to have both. 

 

But to start. A document script is the wrong place to modify form field data. The document script is for setting up scripts and performing initialzation tasks. 

 

To manipulate field data, use the field events related to field data changes. These events are triggered in all cases where field data is changed, whether it's from user input, script changes, or data import. 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
Explorer ,
Dec 13, 2019 Dec 13, 2019

So, according the information you gave me, the solution I applied is :
Add an action to the first field on the document when it's selected.
It launches my javascript code.

In this way, the user just have to click on the first field to apply the script.

Thanks for your help.

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 ,
Dec 13, 2019 Dec 13, 2019
LATEST

Well actually, my idea was to use a value related event, so the update was automatic. For example a custom calculation script. Or plutting a WillCommit keystroke script on the checkbox. 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
LEGEND ,
Dec 12, 2019 Dec 12, 2019

"Final datas are in the xfdf....
The script modify the behaviour of a field in a certain one (data) has a specific value."
Then the data is not final!
"The user open the xfdf then it's automatically importing it on the pdf file.
I want to erase a text field (data) if an element is checked (data)."
Set the text field blank in the XFDF.

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