Skip to main content
September 29, 2016
Question

Calculation Field to be "0" until data entered

  • September 29, 2016
  • 6 replies
  • 374 views

I have a field that calculates a sum from two other fields.

I need the claculated field to be "0" or blank until one of the fields have been entered.

The (A) field would be $10, fillable, starting budget 

The (B) field would be blank but a fillable currency, change in budget (A) field can be a negative of positive dollar field

and the (C) calculation field will be 0 or blank until data is entered into the (B) field for a summation

This topic has been closed for replies.

6 replies

Inspiring
September 29, 2016

That's possible using a custom calculation script, something like:

// Custom calculatino script for field C

(function () {

    // Get the field values

    var A = +getField("A").value;  // Get value as a number

    var B = getField("B").valueAsString;  // Get the value as a string so we can tell of it's blank

    // Set this field's value to the sum if there's a value in field B

    event.value = B ? A + +B : "";

})();

That last line can be translated to English as: If there is an entry in the B field (B ?), then convert the string B to a number (+B) and add it to the A value (A + +B) and set this field's value to the sum (event.value =). Otherwise set this field to blank (: "").

It's equivalent to:

if (B !== "") {

    event.value = A + +B;

} else {

    event.value = "";

}

just more concise.

September 30, 2016

You rock!!!