OnChange Event for Variables
This new feature allows a user to establish CFL procedures that are executed when the value of variable changes (either by calculation or because it is set in CFL).
How it Works
In variable setup (both globally and for an individual product), a new formula box is added to all variable types except Table and Image.
DECLARE OldValue := {oldvalue}; DECLARE NewValue := {newvalue}; NewValue;
Notes
The variable is assigned the value of the CFL statement, which will be NewValue, after the CFL code is executed. This structure allows the user to: * Access the Old Variable Value within the CFL using the local variable OldValue. * Access the New Variable Value within the CFL using the local variable NewValue. * Effectively cancel the change by assigning NewValue := OldValue; * Change what value actually gets saved by assigning it to NewValue.
Examples
Limit Changes based on Security Rights
In this example, we prevent users from making any changes to the variable once it is a saved order unless they have a particular security right. It does that by resetting the new value back to the old value if they don't have permissions. IF (TransHeader.StatusID GESHI_QUOTsidNewGESHI>_)
'' AND (TransHeader.TransactionType = 1) // allow for Orders (1) AND NOT HasSecurityRight(1, 20035) // 1 = Edit, 20035 = Journal Entry THEN NewValue := OldValue ENDIF; ''