Custom Calculation Script Help
Copy link to clipboard
Copied
So I'm attempting to create a custom calculation script and running into kind of an infinite loop, and JS really isn't my forte. Script is as follows.
//Value Check
var v1 = this.getField("Adjust To").value;
var v2 = this.getField("Account Balance").value;
//Calculation
if (v1=="")event.value="";
else {
event.value=v1-v2
}
This script works fine at what I want it to do, which is to take entry from the "Adjust to" Column, subtract it by a the "Account Balance", and then place the result (positive or negative) in the "Adjustment" Column. The issue I run into however, is if I try to mirror this approach in the "Adjust to" Column. Using the same script in both fields but changing the Adjust to script to show the sum of the value of "Adjustment" and "Account Balance" seems to result in a somewhat infinite loop. As entering in either box runs both scripts and ivalidates the intended calculation. In an ideal world, I would really only want each script to run if and ONLY if you manually type data into one field or the other. I'm not sure if theres really a conditional you could input that only enables a script when user data is entered vs calculation data, however I've exhausted every resource I could find. Any input would be appreciated .
Here is a flowchart of what the pdf both will vaguely look like and highlights the intended functions
Copy link to clipboard
Copied
I realized the flowchart was missing an arrow, so it could be confusing so I fixed it.
Copy link to clipboard
Copied
It can be done using one calculation script and check for event.source, but is a bit tricky because "Account Balance" is used in both calculations, so script should be set up to either only calculate second condition if "Adjust To" is empty and other fields are not or to calculate only when value is entered into "Adjustment" field (in which case you would need to enter value first into "Account Balance"). There is another way to use 'Custom keystroke script' in each field:
if(event.WillCommit){
//put script between brackets
}

