Copy link to clipboard
Copied
I am trying to add two fields for a sum in a third field, but only if the 2nd field is a positive number. The two fields I am adding are: “Total Hotel Expenses” and “Total ASP Less Per Diem” to come up with a total in the field “Total Expenses Due”. But if the “Total ASP Less Per Diem” is a negative number then I want it to add it as 0. Any assistance would be greatly appreciated…Thanks Patrick
Copy link to clipboard
Copied
You could do something like this as the custom calculation script for the Total Expenses Due field:
// Custom calculation script
(function () {
// Get the input field values, as numbers
var v1 = +getField("Total Hotel Expenses").value;
var v2 = +getField("Total ASP Less Per Diem").value;
if (v2 < 0) v2 = 0;
// Set this field's value to the sum
event.value = v1 + v2;
})();