Calculations and Auto-Enter CalcsPosted: June 7, 2011
This is fairly basic, but there are several aspects of Calcs and Auto-Enter Calcs that are very important to grasp, and the decision about which to use is sometimes not as straightforward as it might appear.
The data in a simple Calculation field cannot be changed, whereas the contents of an Auto-Enter Calculation can be overridden. So it may be best to think of an Auto-Enter Calc as an ordinary number field which is initially populated via a calculation.
Updating an Auto-Enter Calc
Remember that, if you have NOT ticked “Do not replace existing value of field (if any)”, the Auto-Enter Calc will update if any of the fields within the calculation are changed. If you want to “lock” the contents of the Auto-Enter Calc, make sure that this option is ticked.
Note that, even if this option is NOT ticked, the Auto-Enter Calc will refresh ONLY if at least one of the fields on which the calculation depends are local. Related fields can be used in the calculation, and will make the initial calculation successfully, but the field will NOT update when related fields are changed. So Auto-ENTER Calc is the right name for it – it’s not an Auto-UPDATE Calc when it depends on related fields.
In the example, RBK_cost_autoenter_calc is defined as sessions::SSN_duration * resources::RSC_rate_ph. When data is first entered into the 2 related fields, the cost is calculated accordingly. But when either or both of those values changes, the calculated value in RBK_cost_autoenter_calc remains unchanged. By contrast, RBK_cost_calc, an “ordinary” calc field with the same calculation behind it, is updated when either of the values in the calculation changes. But, as an unstored calc, the value in the field cannot be overridden.
So it’s really about understanding the behaviour of the 2 types of field, and making use of the behaviour. In the room booking example above, it’s probably a desired behaviour that the calculated cost of a resource booking doesn’t change when the hourly rate changes (e.g. going up with inflation, which you wouldn’t want affecting old bookings), but you would almost certainly want the cost field to change when the session duration changes.
If you do need an Auto-Enter Calc field to be updated when related fields are amended, these are some possibilities:
- Use a script trigger to update the Auto-Enter Calc on modification of the related field(s).
- Duplicate the related field(s) in the local table.
A combination of the above is also possible – perhaps do a triggered recalc when the duration changes, which uses the new session duration and the locally stored hourly rate.