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

Use Dynamic stamp to make calculations

KP1860
Registered: Aug 15 2011
Posts: 3
Answered

Using this forum, I have created custom dynamic stamps with various text input fields.
Now I need the stamp to perform a calculation but don't know the script (or where to put it)
I have:
Stamp that asks for "total invoice amount" and prints on the stamp.
I need: 2 more boxes that split the "total invoice amount"
First box would calculate 48% of the "total invoice amount"
Second box would calcualte 52% of the "total invoice amount"
 
I have a number of invoices that need to be approved and processed with this exact split amount. Can the stamp split it for me?

My Product Information:
Acrobat Pro 9.0, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
To set the value of the total invoice amount field, you must be using a calculate script to set the field value. In that same script, just calculate the two percentages and set the values of the other fields. If you'd specific help with the script, post again with what you already have and include the field names of the other two fields.
KP1860
Registered: Aug 15 2011
Posts: 3
Thanks- Here's what I have:

Field 1: box pops up and asks "Code". User inputs accounting code

Field 2: Box pops up and asks for "Invoice Amount". User enters amount.

Current Script for Field 2
var cAsk = "Invoice Amount" ;
var cTitle = "Invoice Amount: ";
if(event.source.forReal && (event.source.stampName == "#J2ptEmYC91A9ZmP5LsJlBD"))
{
var cMsg = app.response(cAsk, cTitle);
event.value = cMsg;
event.source.source.info.exhibit = cMsg;
}

After this I need Field 3 to show 48% of field 2
Field 4 to show 52% of field 2
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
Accepted Answer
Add something like the following to the end of your existing script:

if (!isNaN(+cMsg)) {
getField("Text1").value = util.printf("%.2f", .48 * +cMsg);
getField("Text2").value = util.printf("%.2f", .52 * +cMsg);
} else {
getField("Text1").value = "";
getField("Text2").value = "";
}

It first attempts to convert the input to a number and tests to make sure the result is a number. It then sets the other fields values to the calculated amounts (to two decimal points), or blanks the fields if the input does not convert to a number (e.g., if the user enters letters.) Change to suit your needs.

Also, change the field names "Text1" and "Text2" to match the field names you're using.
KP1860
Registered: Aug 15 2011
Posts: 3
It worked!! Thanks so much.