2 Replies Latest reply on Sep 29, 2014 12:44 PM by proservIT

# Custom Calculation Script - Multiplication IF

Hey Adobe peeps, need help here. I'm not a programmer by any stretch of the imagination, but I am resourceful, BUT I have yet to find a concrete answer for this, nor can I get any of my test formula's to work.

I have a fillable PDF that is used in a field service environment where employees track their time. I want them to be able to input the data in i.e. hours*rate and it automatically populate the price/cost. Now this is very easy to do with the built in product function, but the problem here is that they have multiple fields to fill out. See below.....

So basically the "Extended Price" field depends on what they enter into either the "Days", "ST Hours", "Rate, "OT Hours" or "Rate" fields.

The calculation should be based on 2 of the 5 fields being filled out. For example, here are the 3 possible scenarios:

Scenario 1: SP Extended Price1=SP Days1*SP ST Rate1

Scenario 2: SP Extended Price1=SP ST Hours1*SP ST Rate1

Scenario 3: SP Extended Price1=SP OT Hours1*SP OT Rate1

They won't ever fill out any more than 2 of the fields so it needs to be an 'if' type of function. I've spent hours on this already, like I said, I'm not a programmer.

• ###### 1. Re: Custom Calculation Script - Multiplication IF

If they really won't be filling in more than one of those sets of fields, the custom calculation script could be:

(function () {

// Get the field values, as strings

var s1 = getField("SP Days1").valueAsString;

var s2 = getField("SP ST Rate1").valueAsString;

if (s1 && s2) {

event.value = +s1 * +s2;

return;

}

var s3 = getField("SP ST Hours1").valueAsString;

if (s2 && s3) {

event.value = +s3 * +s2;

return;

}

var s4 = getField("SP OT Hours1").valueAsString;

var s5 = getField("SP OT Rate1").valueAsString;

if (s4 && s5) {

event.value = +s4 * +s5;

return;

}

// If none of these apply, set the field to blank

event.value = "";

})();

• ###### 2. Re: Custom Calculation Script - Multiplication IF

Thank you very much, I appreciate it!