Hi @LavanyaS,
Please find below the detailed explanation that might help you understand the Loop Rule mapping better:
Loop Rule Mapping & Script Explained
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.
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
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
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"]
}