How to make sure that action is executed only once

Most rules in Aware IM are un-ordered, i.e. Aware IM does not guarantee the order in which the rules will be evaluated. Consequently, the same rule may be submitted for evaluation several times and so its action may be executed several times as well (see the “Rule Evaluation” section). For actions that modify attribute values this is not a problem, provided that the last execution of the action sets the attribute to the correct value. Aware IM guarantees that this will be the case provided that rules are consistent and independent of one another.

What about rules that perform a different action, for example report errors or request services? Will they be executed several times as well? The answer is no, because Aware IM assigns different priorities to rules invoking such actions to make sure that they are evaluated after the rules that modify attributes (see the “Rule Priorities” section ). Even so, it is probably not a very good idea to execute certain actions from rules attached to business objects without taking special precautions, as the rules will be evaluated every time the object is changed. For example, let us consider the following rule:

IF Account.State = 'Open' THEN 
   CREATE AccountOpeningLetter WITH 
    AccountOpeningLetter.Addressee = Account.Holder 

The way the rule is written the letter to account holder will be created every time the Account object is changed (provided that it is in the “Open” state) – even if changes have nothing to do with the state of the account. This is not what we want. What we really want to do is to create a letter only when the account becomes open. Therefore we have to write our rule as follows:

IF Account.State WAS CHANGED TO 'Open' THEN 
   CREATE AccountOpeningLetter WITH 
    AccountOpeningLetter.Addressee = Account.Holder 

In certain cases it may even be necessary to introduce a state or some other attribute to check whether an action has been performed, for example:

IF Policy.ExpiryDate<=CURRENT_DATE AND Policy.LetterCreated='No' THEN 
   CREATE ExpiryLetter WITH 
    ExpiryLetter.Addressee = Policy.Holder 

Note that it is not necessary to take any precautions when sending e-mails – Aware IM will send all e-mails only after all rules have been evaluated (more precisely, e-mails just like any other notifications are sent when the current transaction is committed – see the “Rules and Transactions” section).

  • Last modified: 2022/12/15 05:06