How to Use the Loop Rule with Exit Condition in Reels

Hi Team,

This post explains how to configure and use the Loop Rule with an Exit Condition in Reels to iterate over a list of names and stop processing when a specific condition is met.


:blue_book: Use Case

The objective is to:

  • Iterate through an array of name objects.
  • Terminate the loop when the name "Rakesh" is found.
  • Return a Boolean flag (true) once the condition is satisfied.

:brick: Step-by-Step Configuration

:small_blue_diamond: 1. Script Node

We begin with a SCRIPT rule that defines a static array of objects:

OP_out = [
  { "name": "Sinan" },
  { "name": "Rakesh" },
  { "name": "Fawaz" }
];

:pushpin: Global Output Mapping:

  • Output key: Scriptoutput
  • Mapped from the script’s output field: out

:small_blue_diamond: 2. Loop Rule Setup

Loop Configuration:

  • Sequence Field: Scriptoutput (the array defined in the script)
  • Sequence Type: Array of Objects
  • Output Type: Object

Loop Input Mapping:

  • name β†’ Maps to the name field of each object in the sequence

Loop Output Mapping:

  • status β†’ Captures whether the loop condition has been met (true or false)

:pushpin: Global Output Mapping:

  • Map status (loop output) to global key Loopoutput

:small_blue_diamond: 3. Decision Table Rule (Inside Loop)

A Decision Table is used within the loop to determine when to exit. The condition is defined as follows:

Condition (name) Result (status)
Equals "Rakesh" true
Default false

:pushpin: This status flag is evaluated after each iteration.


:small_blue_diamond: 4. Exit Condition in Loop

The Loop Rule is configured with the following exit condition:

status == "true"

:white_check_mark: As soon as this condition is met (i.e., name == "Rakesh"), the loop stops.


:white_check_mark: Final Output

After successful execution, the output will appear as:

{
  "script out": [
    { "name": "Sinan" },
    { "name": "Rakesh" },
    { "name": "Fawaz" }
  ],
  "loop output": "true"
}
9 Likes