How Context is Formed
The Context is used by AwareIM to resolve values of attributes of business objects during evaluation of rule collections (both ordered and un-ordered – see Evaluation of Rule Collections). It is important to emphasize that each rule collection has its own Context; there is no single Context that is shared by all rule collections. For example, let us suppose that we are executing a rule collection representing rules of a process. This rule collection has a Context associated with it (let us not worry for now how it was formed). If some action modifies the value of an attribute of some business object AwareIM starts evaluating the rules attached to this business object. Before doing so it assigns a new Context to this collection of rules (again let us not worry for now what gets written into this Context). Once the rules attached to the business object finish execution, the Context associated with the rule collection is discarded and AwareIM continues evaluation of the process rules. Now, if some action of these rules starts another process AwareIM assigns another Context and starts evaluating the rules of a sub-process. When the sub-process finishes AwareIM discards the Context and returns to the evaluation of the rules of the original process.
Let us now have a look at what gets written into the Context and when. The contents of the Context is changed under the following scenarios:
- Instances of the business objects found by the
FINDandPICK FROMactions are written into the Context of the rule collection that invokes these actions1).
For example, let us look at the following process:FIND Driver WHERE Driver.Name = 'John Smith' Driver.Age = 40
The first rule in this process finds the driver with the name John Smith. If such an instance is found it is written into the Context.
- When AwareIM starts evaluating the rules attached to a business object the instance of the business object is written into the Context. The instance is either taken from the parent Context (such as when an instance of a business object is modified by a process) or is provided by the external request (such as when a user changes attribute values on the business object form and submits the changes to the system).
In the process from the first scenario the second rule modifies the attribute of the driver’s instance found by the previous rule. If theDriverobject has rules attached to it AwareIM assigns a new Context to these rules, writes the instance of theDriverfrom the process Context into the new Context and starts evaluating rules of theDriverobject.
- When AwareIM starts executing a process the instances of the business objects representing process input are written into the Context. The instances are taken from the parent Context. \\For example, consider the following process:
FIND Policy WHERE Policy.MyDriver.Name = 'John Smith' CalculatePremium
Here we assume that
CalculatePremiumprocess that calculates the premium of the policy has thePolicyobject declared as its input. The first rule finds the policy belonging to John Smith and writes it into the Context of the main process. Then AwareIM creates a new Context for theCalculatePremiumprocess, writes the instance of thePolicyfrom the main process’s Context into the new Context and starts evaluating rules of theCalculatePremiumprocess. - When a new instance of a business object or notification is created by the
CREATEaction AwareIM writes the contents of the parent Context into the new Context which is created when rules attached to the business object or notification are evaluated.
In other words the Context of the parent rule collection is available when a new business object or notification are being created. For example consider the following process,
FIND Policy WHERE Policy.ExpiryDate < CURRENT_DATE CREATE ExpiryEmail SEND ExpiryEmail TO Policy.Driver
The first rule of the process finds the expired policy and puts the found instance into the Context of the process. The second rule of the process creates the notification ExpiryEmail and evaluates any rules attached to the creation of this notification2). The new Context is assigned to these rules, but now not only the created notification is written into this Context but the entire contents of the existing Context is written into the new Context as well. Therefore in this example Policy instance is available to any initialization rules of the notification. The created notification is also written into the original Context (as a result of creation), so in this particular case both Contexts have identical contents.
FIND action, as they are always implicitly present in any Context:
- An instance of a business object representing logged in user (must be a member of the
SystemUsersgroup) – this instance can be referred to usingLoggedInprefix (see Instance Prefixes), for exampleLoggedInLibraryMemberwhereLibraryMemberis a business object belonging to theSystemUsersgroup. - Instances of intelligent business objects with Business or System intelligence types. There are always only single instances of such business objects in the system, so they can always be unambiguously resolved.
- An instance of the SystemSettings object.
Driver object found by the FIND action, if the action finds several instances of the Driver object all these instances are written into the Context. Consequently the action that modifies the Age attribute modifies every single instance of the Driver object found by the FIND action. Similarly in scenario 5 if there are several expired policies the email is sent to owners of each policy.
CREATE or ENTER NEW actions or found by the FIND or PICK FROM actions are not written into the Context of the un-ordered rule collection. Instead these instances are made available only within the action block that contains the FIND (PICK FROM) or CREATE (ENTER NEW) actions. This means, for example, that it is quite meaningless to attach rules to a business object, which have single FIND action. However, having an action block that finds some object and then does something with the found instance within this block may be quite meaningful.