While Rule

  • Updated

While Rule is a condition whose expression, when evaluated to true (meaning the condition is satisfied), executes an associated set of actions and other rules, and repeats this as long as the condition is true.

While Rules are similar to If/Then Rules in InRule and follow the general form of while-do-action. While Rules can be added to Rule Sets, If/Then/Else Rules, If/Then Rules and other While Rules.

mceclip0.png

Name

Specifies the name of the rule.

While

An expression that when evaluated to true (or satisfied) causes the rule engine to execute the actions listed under "Do". The list of sub-rules and actions will be executed as long as the expression is true.

Please see About Expressions for more information on how to build a rule condition.

Iterating through a Collection

A common use of the While Rule is to iterate through a collection. It's generally good practice to first check if your logic can be managed by using the execute member rule set action or by setting rules and calculations at the collection member level, then use aggregate functions to make decisions across the collection, essentially avoiding the need to code a loop. In some situations though, it may not be feasible to achieve a particular process in this manner, rolling sums and grouping being two examples. In these cases, the While Rule can be applied to achieve granular control of processing logic across a collection.

mceclip0.png

Aspects of this approach worth noting are:

  • collections use a 1-based index for iteration within rules
  • use of the Count() function to define the upperbound of the iteration
  • use of Items(itemIndex).Units syntax to ordinally refer to the field of a collection member

Was this article helpful?

0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.