We have a form that includes a field where it autocalculates the amount of commission a sales guy will get based off the Job Total and Percentage they fill in.
How can I make it so the last field (commission total) can be autocalculated but with also the ability to be manually overwritten?
Right now, I have the field to calculate with Simplified Field Notation:
(Commission_Row_1 * Row1) / 100
"Commission_Row_1" is the Job Total
"Row1" is the Percentage of Commission
Overriding a calculation can be tricky. Just in general, this line of code will disable a calculation.
event.rc = false;
But the problem is detecting the situation where the calculation is first disabled, then the situation where it is enabled.
An easy solution is to use a checkbox. For your case it might be labeled as "Calculated Commission". Then the check is used to both override the calculation and set the ReadOnly value of the field.
It is also possible to detect keystrokes and set state variables that determine whether the calc is overridden. But this is much more difficult. What setup do you want?
Thank you for your response!
If I'm understanding correctly, the sales person would check the box which will allow them to override the autocalculated Commission Total and manually input an amount in that same field?
Can you walk me through the steps on how to do this?
Let's say the checkbox is named "SetCommission".
You're going to need to change the calculation to a custom script. Here's the code
event.rc = this.getField("SetCommission").value != "Off";
event.value = (this.getField("Commission_Row_1").value * this.getField("Row1").value) / 100;
this.getField("commission total").readonly = event.target.value == "Off";
this is a great solution for me. Could you add a code here so that the value is calculated again if the field is set to 0 (or cleared by click)?