Skip to main content
robertl87337782
Participant
August 27, 2018
Answered

If GTE is a total and CAE us a variable. What is the script for BDC if BDC = CAE-GTE if CAE>GTE or blank if CAE = 0 or is blank? A second script BDE where BDE=GTE-CAE if GTE>CAE or blank if CAE>GTE?

  • August 27, 2018
  • 1 reply
  • 827 views

If GTE is a total and CAE us a variable.  What is the script for BDC if BDC = CAE-GTE if CAE>GTE or blank if CAE = 0 or is blank? A second script BDE where BDE=GTE-CAE if GTE>CAE or blank if CAE>GTE?

This topic has been closed for replies.
Correct answer George_Johnson

They are names of fields (cash advanced to employee, grand total expenses - the other fields are BDC balance due company and BDE balance due employee).


OK, the custom calculation script of the BDC field could be something like:

(function () {

    // Get the input field values, as numbers

    var CAE = +getField("CAE").value;

    var GTE = +getField("GTE").value;

    // Set this field's value

    event.value = CAE > GTE ? CAE - GTE : "";

})();

That final line of code is equivalent to the following if/else statement:

    if (CAE > GTE) {

        event.value = CAE - GTE;

    } else {

        event.value = "";

    }

This should help you figure out the other calculation script, but if you get stuck, post again.

1 reply

Inspiring
August 27, 2018

Have you looked a the JavaScript Reference Provided by MDN?

Look under Statements and Expressions and Operators.

robertl87337782
Participant
August 28, 2018

I have looked there, and some examples of scripts, but they all begin too far beyond where I am.  I have tried;

scripting  value to be entered in BDC:

if (CAE>GTE) = GTE - CAE;

else if (CAE=" ") = " ";

else if (GTE>CAE) = " "

Scripting value to be entered in BDE:

if (CAE>GTE) = " ";

else if (GTE>CAE) = GTE-CAE

When I enter these in the custom calculation script for a PDF form in Acrobat I get syntax errors.

This is just a simple PDF form and I have no experience with Javascript (the only experience I have in scripting was a required class 20-years ago using BASIC on a TRS 80.

Inspiring
August 28, 2018

Are CAE and GTE the names of fields, or something else?