Evaluation of Rules Containing WAS CHANGED expressions

Evaluation of rule conditions containing WAS CHANGED expressions (and also expressions that track changes in the list – WAS ADDED TO, WAS REMOVED FROM, WAS CHANGED FROM – see WAS CHANGED Expression) is somewhat different from evaluation of other expressions. Whereas most expressions check the absolute value of an attribute (such as If Driver.Age > 70), WAS CHANGED expressions check the relative value of the attribute – that is, the current value of the attribute compared to the old value of the attribute. The question is which value is considered to be “old”? Similarly if an expression checks whether some element has been added to a list, the question is – added when?

Before answering this question we must explain the meaning of the term last stable version of a business object instance. The last stable version is the version of the business object instance that is stored in the system and no rule processing of the rules attached to the object is occurring. When an instance of the business object is modified and rules attached to this business object start to be evaluated the instance of the business object is considered to be in an unstable state. When rule evaluation and action execution for the instance of the business object finish the instance of the object moves to a stable state again. Any new modification to the business object instance from the outside (for example, by a user or by a process) will cause rule evaluation and action execution to occur again and move the object back to the unstable state.

Now we can answer the question which value Aware IM considers to be “old” when evaluating WAS CHANGED expressions. The “old” value is the value corresponding to the last stable version of the business object instance. For example, consider the following rule:

IF OLD_VALUE(Policy.State) = 'CALCULATED' AND Policy.State WAS CHANGED THEN 
   REPORT ERROR 'Cannot change state of the policy once it is calculated' 

OLD_VALUE here is the function that returns the value of the attribute corresponding to the last stable version. Let us assume that the value of the State attribute currently stored in the system is CALCULATED. Let us assume that a user brings up a policy form and changes the value of the State attribute to NEW. When the changes to the policy are submitted Aware IM starts evaluating the policy rules. When evaluating the rule above it will compare the value of the last stable version of the State attribute (CALCULATED) with the current value (NEW) and trigger the REPORT ERROR action.

Note that WAS CHANGED expression will return true each time it is evaluated provided that the current value is different from the value of the last stable version. So in our example if a rule above is evaluated again as a result of execution of other actions it will still return TRUE. It will keep returning TRUE while rules are being evaluated for the instance of the business object.

Once rule evaluation finishes the instance of the business object moves to the stable state again. Consider the following rules on the Policy object:

Rule 1

IF Policy.State WAS CHANGED THEN 
   DoSomething 

Rule 2

IF Policy.MyDriver.Age > 70 THEN 
   Policy.Premium = 200 

Rule 3

IF Policy.Premium = 200 THEN 
   Policy.State='BIG PREMIUM' 

Let us assume that there is a policy for a driver aged 45, the value of Premium is 100 and the policy state is NORMAL PREMIUM. If a user changes the age of the driver to 50, neither of the actions of the three rules will be triggered (the value of the State attribute for the current and last stable versions are the same and the age is still less than 70). Now, if the user changes the age of the driver to 75 (again without changing the state of the policy) the following will happen after the initial evaluation of rules:

  1. Condition of Rule 1 will not hold because the current state is equal to the state of the last stable version
  2. Condition of Rule 2 will hold and so its action will be placed on the agenda
  3. Condition of Rule 2 will not hold initially because premium is still 100

After the premium is changed to 200 by the action of Rule 2 the action of Rule 3 will be triggered. This action will change the value of the State attribute to BIG PREMIUM. This will cause the conditions of Rule 1 to be evaluated. Now, the current value of the State attribute will be different from the value of the last stable version and DoSomething will be triggered. After that the policy instance will move to the stable state again so the “stable” value of the State attribute becomes BIG PREMIUM. If now the user changes the driver’s age to 80 the action of the first rule will not be triggered.

Evaluation of list tracking expressions is quite similar – they compare the condition of the list in the last stable version of the business object with the current condition.

  • Last modified: 2022/09/13 18:15