4 Replies Latest reply on Aug 27, 2013 12:07 PM by teresamcgill

# Java Calculation for Acrobat PDF

I need help with custom calculation script. Three cells (A,B,C,D) A, B and C are the data fields and D is the total field

IF (A-B-C)>0    then D=0

ELSE D=(A-B-C)*-1

So if the total calculated produces a positive number, the field should read '0". BUT, if the total calculated produces a negative number, the field should read the actual calculated number (multiplied by –1 so the number shows as a positive number).

• ###### 1. Re: Java Calculation for Acrobat PDF

Try something like:

// Custom calculation script

(function () {

// Get the field values, as numbers

var v1 = +getField("A").value;

var v2 = +getField("B").value;

var v3 = +getField("C").value;

// Perform the calculation

var v4 = v1 - v2 - v3;

// Set this field's value based on the result

event.value = v4 >= 0 ? 0 ; -v4;

})();

• ###### 2. Re: Java Calculation for Acrobat PDF

I get a syntax error: Missing : in conditional expression, line 14, col 1

(function () {

var v1 = +getField("assets_total").value;

var v2 = +getField("income_total").value;

var v3 = +getField("lump_total").value;

var v4 = v1 - v2 - v3;

event.value = v4 >= 0 ? 0 ; -v4;

})();

• ###### 3. Re: Java Calculation for Acrobat PDF

Oops, that one line should be:

event.value = v4 >= 0 ? 0 : -v4;

• ###### 4. Re: Java Calculation for Acrobat PDF

It worked - thanks soooo much!