Update
You can use the Update function to improve engine performance and prevent endless loop scenarios. In a typical scenario, an object is updated by a rule and then needs to be reasserted into the engine to be re-evaluated, based on the new data and state.
Take the two rules that follow as an example. Suppose that objects ItemA and ItemB already exist in working memory. Rule 1 evaluates the Id property on ItemA, sets the Id property on ItemB, and then reasserts ItemB after the change. When ItemB is reasserted, it is treated as a new object and the engine re-evaluates all rules that use object ItemB in the predicates or actions. This ensures that Rule 2 is re-evaluated against the new value of ItemB.Id, as set in Rule 1. Rule 2 may have failed the first time it was evaluated, but evaluates to true the second time it is evaluated.
Rule 1
IF ItemA.Id == 1
THEN ItemB.Id = 2
Assert(ItemB)
Rule 2
IF ItemB.Id == 2
THEN ItemB.Value = 100
This ability to reassert objects into working memory allows the user explicit control over the behavior in forward-chaining scenarios. A side effect of the reassertion in this example, however, is that Rule 1 is also re-evaluated. Because ItemA.Id was not changed, Rule 1 again evaluates to true and the Assert(ItemB) action fires again. As a result, the rule creates an endless loop situation.
Warning The default maximum loop count of re-evaluation of rules is 2^32. For certain rules, the policy execution could last for a long time. You can reduce the count by adjusting the Maximum Execution Loop Depth property of the policy version.
You need to be able to reassert objects without creating endless loops, and the Update function provides this capability. Like a reassert, the Update function performs Retract and Assert of the associated object instances, which have been changed from rule actions, but there are two key differences:
- Actions on the agenda for rules where the instance type is only used in the actions (not the predicates) will remain on the agenda.
- Rules that only use the instance type in the actions will not be re-evaluated.
Therefore, rules that use the instance types in either the predicates only or both the predicates and actions will be re-evaluated and their actions added to the agenda as appropriate.
Changing the preceding example to use the Update function ensures that only Rule 2 is re-evaluated. Because ItemB is only used in the actions of Rule 1, Rule 1 is not reevaluated, eliminating the looping scenario.
Rule 1
IF ItemA.Id == 1
THEN ItemB.Id = 2
Update(ItemB)
Rule 2
IF ItemB.Id == 2
THEN ItemB.Value = 100
However, it is still possible to create looping scenarios. For example, consider the following rule.
Rule 1
IF ItemA.Id == 1
THEN ItemA.Value = 20
Update(ItemA)
Because ItemA is used in the predicate, it is re-evaluated when Update is called on ItemA. If the value of ItemA.Id is not changed elsewhere, Rule 1 continues to evaluate to true, causing Update to once again be called on A. The rule designer must ensure that looping scenarios such as this are not created.
The appropriate approach for this will differ based on the nature of the rules. The following is a simple mechanism to solve the problem in the preceding example.
Rule 1
IF ItemA.Id == 1 and ItemA.Value != 20
THEN ItemA.Value = 20
Update(ItemA)
Adding the check on ItemA.Value prevents Rule 1 from evaluating to true again after the actions of Rule 1 are executed the first time.
.NET objects
The .NET object is retracted and asserted with the behavior documented earlier. The Update function may be used in the Business Rule Composer with a reference to the class, as with the Assert, Retract, or RetractByType functions.
TypedXmlDocument
All object instances that were created from the TypedXmlDocument and have been changed are retracted and asserted. Passing a TypedXmlDocument to the Update function is performed in the same manner as with the other functions.
As with reassert, the update mechanism may be carried out on child nodes. Consider a simple example in which the Update function is being performed on a node P, the parent of node C. If node C is dirty, which means that at least one of its fields has been changed as a result of rule actions, node C will be updated in this case. If node C is not dirty, it remains unchanged.
TypedDataTable
If Update is called on a TypedDataTable, Update is called by the engine on all associated TypedDataRows. Update may also be called on individual TypedDataRows.
DataConnection
Update of a DataConnection is not supported. Use Assert instead.
To download updated BizTalk Server 2004 Help from www.microsoft.com, go to http://go.microsoft.com/fwlink/?linkid=20616.Copyright © 2004 Microsoft Corporation.All rights reserved.