These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Changing the execution order of JavaScript on Stamps

kmiffy
Registered: Nov 15 2011
Posts: 5
Answered

I've created a custom stamp with multiple fields on Acrobat X. Since I didn't enter the JavaScript in the order that I wanted the popups to show up when stamping, they show up out of order. Is there a way to rearrange the order in which the JavaScript runs without having to start over from scratch?

My Product Information:
Acrobat Pro 10.0, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
There are two ways to control the order of popups. The best method is to place all the scripts for setting the various fields into a single calculation script. A single script is much easier to control, maintain and debug. In fact, if you have the skills or tools, to create a custom dialog, then you can placed everything in a single dialog and make things easier, and nicer looking, for the users.


The other method is to modify the calculation order. This method can be problematic because Acrobat will automatically modify the order under certain circumstances. And you've got scripts spread out all over the place.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

kmiffy
Registered: Nov 15 2011
Posts: 5
So I don't have the tools or much skills, but is it possible to do the single dialog calculation from within Acrobat? I'm currently going into the properties of each field and copying and pasting the JavaScript in the calculation tab. I did see all the scripts in one place under Tasks> Other Tasks> JavaScripts> Edit All JavaScripts, but I got scared by the "Do not Edit" warning. Would moving the order here fix things? Sorry about my very limited knowledge of JavaScript.As for modifying the calculation order, where would I go to do that?

Thanks for your help.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Accepted Answer
Do not use the "Edit All Scripts"
Right now you are probably using scripts that look like this on the calculation script in each individual field.

if(event.source.forReal && (event.source.stampName == "#MyStamp"))
event.value = app.response("Please Enter Data");


A better solution is to place all the scripts for a single stamp into the calculation script for a single field. Like this:

if(event.source.forReal && (event.source.stampName == "#MyStamp"))
{
// For field the script is on
event.value = app.response("Please Enter Text 1 Data");

// For the other fields
this.getField("Text2").value = app.response("Please Enter Text 2 Data");
this.getField("Text3").value = app.response("Please Enter Test 3 Data");
}


Alternatively, if you want to keep everything the same as it is now, then set the calculation order from the Form edit mode. On the "Task" panel, select "Other Tasks > Edit Fields > Set Field Calculation Order". You can easily look this kind of thing up in the Acrobat Help docs. Just type "Calculation Order" into the search box.


Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

kmiffy
Registered: Nov 15 2011
Posts: 5
Wow, your suggested script all entered in one field is so much easier to handle. Thank you so much!
kmiffy
Registered: Nov 15 2011
Posts: 5
Since I'm now feeling kind of brave, I wanted to make two improvements to my stamp. By reading another one of your forum answers, I've figured out that I could return a current date in one of the fields by inserting

this.getField("Text 1").value = util.printd(mmm dd, yyyy”, new Date());

But I can't figure out how to return a sum of other fields. I have the following fields "AMT 1", "AMT 2", and "AMT 3". "AMT 1" will always have an amount but "AMT 2" and "AMT 3" may be left blank at times. I'd like the sum of those three fields to show up on the field "INV TOTAL". Is that possible? All those fields have been formatted as numbers.


thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Calculations on a stamp are no different than calculations on a regular form. Figure it out for one and you have the other.

Are you using the built-in "Sum" on the calculate tab of a form field? The built-in calculations are sensitive to field names. The names should not contain any spaces or special characters.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

kmiffy
Registered: Nov 15 2011
Posts: 5
Oh, silly me--I was trying to make it harder for myself by trying to insert JavaScript to get the sum. I didn't notice that one of the calculation options is to get the sum of selected fields. Thanks for pointing me in the right direction.