Input and Output Mapping in a loop tree

Hi Team,

I am exploring the Loop tree rule in Reels. But unable to find the correct way to map the inputs and outputs. Can you guide me with the same?

For example,

In the above rule group, in script I am providing,
OP_cars = [
{ make: “BMW”, year: 2023, models: [“A780”, “098”] },
{ make: “Ferrari”, year: 2022, models: [“B765”] },
{ make: “Audi”, year: 2021, models:[“A345”] }
];
I need to loop through the array of objects and get the models as a concatenated list.
Expected output: modelOutput: [“A780”, “098”, “B765”, “A345”]

Below is my mapping



Thanks,
Lavanya S

3 Likes

@Rocky @Muhammed_Sinan please help

2 Likes

Hi @LavanyaS,

Please find below the detailed explanation that might help you understand the Loop Rule mapping better:

Loop Rule Mapping & Script Explained

:small_blue_diamond: 1. Input Data

In your first SCRIPT node, you define:

OP_cars = [
  { "make": "BMW", "year": 2023, "models": ["A780", "098"] },
  { "make": "Ferrari", "year": 2022, "models": ["B765"] },
  { "make": "Audi", "year": 2021, "models": ["A345"] }
];

This exposes cars as an output key — an array of objects — and becomes the sequence input for the Loop rule.


:small_blue_diamond: 2. Loop Rule Setup

➤ Sequence Configuration:

  • Sequence Field: cars
  • Sequence Type: Array of Objects
  • Output Type: Object (since we’re returning a single object with a key)

Input Field in Loop Rule:

You create:

  • models → this maps to each item’s models field from the cars array

This field will be used in the loop’s script as IP_models.

Output Field in Loop Rule:

You create:

  • concatenatedModel ( → this stores the running array of all models

This will be used as:

  • IP_currentArray in the script (input to loop rule)
  • OP_concatenatedModel as output from the loop script

:small_blue_diamond: 3. Loop Script Rule

Your script inside the loop:

if (!Array.isArray(IP_currentArray)) {
    IP_currentArray = [];
}
IP_currentArray.push(...IP_models);
OP_concatenatedModel = IP_currentArray;

Key explanation:

  • IP_models: contains current iteration’s models
  • IP_currentArray: accumulates models across iterations (comes from conctenatedModel)
  • OP_concatenatedModel: returns the updated array in each loop

:small_blue_diamond: 4. Global Output Mapping

At the end of the loop rule:

  • conctenatedModel (from loop output) is mapped to global key ModelOutput
  • cars from initial script is directly mapped to global output as cars

Final Output

{
  "cars": [
    { "make": "BMW", "year": 2023, "models": ["A780", "098"] },
    { "make": "Ferrari", "year": 2022, "models": ["B765"] },
    { "make": "Audi", "year": 2021, "models": ["A345"] }
  ],
  "ModelOutput": ["A780", "098", "B765", "A345"]
}
4 Likes

Hi @Rocky,
Thank you for the detailed response. I will try this out.

3 Likes