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.
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.
Step-by-Step Configuration
1. Script Node
We begin with a SCRIPT rule that defines a static array of objects:
OP_out = [
{ "name": "Sinan" },
{ "name": "Rakesh" },
{ "name": "Fawaz" }
];
Global Output Mapping:
- Output key:
Scriptoutput - Mapped from the scriptβs output field:
out
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 thenamefield of each object in the sequence
Loop Output Mapping:
statusβ Captures whether the loop condition has been met (trueorfalse)
Global Output Mapping:
- Map
status(loop output) to global keyLoopoutput
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 |
This status flag is evaluated after each iteration.
4. Exit Condition in Loop
The Loop Rule is configured with the following exit condition:
status == "true"
As soon as this condition is met (i.e., name == "Rakesh"), the loop stops.
Final Output
After successful execution, the output will appear as:
{
"script out": [
{ "name": "Sinan" },
{ "name": "Rakesh" },
{ "name": "Fawaz" }
],
"loop output": "true"
}