Describe the issue/error/question
Hello guys,
I wonder how you merge data using the ‘Code’ node when there’s a loop inside another loop and you want to merge data separately for each nested loop.
So I created this example workflow where I get data (Customer Datastore) and do 2 runs (represented by ‘some_data_im_getting’ node) on the first 2 items. So in total 2 runs outside loop and 4 runs inside loop (2 for each item).
In the example workflow, the ‘merge_loop_runs’ node should output 2 items in the 1st run of the outside loop (only Jay Gatsby), and 2 items in the 2nd run (only José Arcadio Buendía). Now it outputs 2 items in the 1st run (Jay Gatsby) and 4 in the 2nd run (Jay Gatsby and José Arcadio Buendía).
To make things more complicated, in my real workflow the 2 runs of the nested loop is a limit - so it could be the nested loop runs only once (there’s one additional condition in the ‘IF’ node that can end the loop).
In theory, I know the i parameter in ‘merge_loop_runs’ node should be equal to 0 for the 1st run of outside loop and to sum of init - 1 (where init variable is from ‘increment_init’ node of previous runs) for every consequent run but I don’t know how to put it in code (or if it’s even possible).
Thank you.
What is the error message (if any)?
No errors.
Please share the workflow
Share the output returned by the last node
In the example workflow above, the expected output of the last node for the second run of the ‘split_in_batches_customer_datastore’ loop is just 2 last items instead of 4.
Information on your n8n setup
- n8n version: 0.215.2
- Database you’re using (default: SQLite): SQLite
- Running n8n with the execution process [own(default), main]: own
- Running n8n via [Docker, npm, n8n.cloud, desktop app]: Docker
