Iterative rule

An iterative rule goes through a list, checking each item one by one. If an item meets the rule's criteria, the rule does something to that item. The "iterative" part means the rule moves through the list in order, item by item. It’s not about remembering past items or repeating the rule on the same item. Each item is checked separately, and action is taken when needed.


Key Differences to Normal Rule

  • Execution:
    Normal rules work on a specific piece of data or a single item. Iterative rules go through all items in a list, one at a time.

  • Purpose:
    Use a normal rule for a single check. Use an iterative rule when you need to apply the same logic to every item in a list.

Normal rules target individual data points. Iterative rules are for situations where you need to check a whole series of items the same way.


How to Change a Rule from Standard to Iterative

  1. Access the Rule’s Conditions:
    Click on the “Apply rule when” section of your rule configuration.

  2. Change to Iterative Rule:
    In the selector, select “Apply on all in the list:”.

  3. Specify the Data to Iterate Through:
    An input field appears. Enter the path to the list you want to process.
    For example, if your data has an array named transactions, enter $.transactions. The path can point to an array, a single value, or an object. A missing path is treated as a list with one empty item.

The rule evaluates its conditions once for each item. Its usual “all” or “any” logic applies to that item alone. The rule is counted as hit when at least one item meets its conditions. Its actions run only for items that meet the conditions. Items that do not meet them remain unchanged.

Items are processed in order from first to last. The actions for one item take effect before the next item is checked.

image-20240106-172020.png

Using $.__item in Iterative Rules

When you define an iterative rule, each item in the list is checked on its own. To refer to data from the current item, use $.__item in your field paths.

What $.__item Does

$.__item always points to the current item being processed. Any path starting with $.__item is resolved against the current item, not the parent object.

Example

If your array is transactions and each transaction has an amount field:

  • To set the array for iteration:
    Use $.transactions

  • To reference the amount for the current transaction:
    Use $.__item.amount

In Rule Conditions and Actions

  • In conditions, use $.__item.field (for example, $.__item.status) to read a property of the current item.

  • A path without $.__item reads from the whole data object. A condition can compare a field on the current item with a value outside the list.

  • In actions, a target that starts with $.__item writes to the current item. For example, $.__item.flag sets flag on that item.

  • An action target without $.__item writes to the named location in the data once for each matching item.

Summary Table

Where UsedWhat to WriteWhat It Refers To
Iterate over$.transactionsThe array you want to process
Item property$.__item.amountamount of current item
Nested property$.__item.foo.barfoo.bar of current item