Differentiate output for runs in Loop Over Items

Describe the problem/error/question

I have a simple content creating workflow running multiple instances (manual trigger, not automated). Each item is processed with a Loop Over Items (#1).

The base content gets separated by headings and Split Out.

In the first loop there is another Loop Over Items (#2) which elaborates on each heading separately after Splitting Out.

When the second input item in loop #1 runs, the flow cannot pick up the difference between runs. It alwasy picks the ouput of the first run, not the actual run.

Split Out ouput is correct. I have tried referencing the Split Out output multiple ways:
{{ $json.sections }}
{{ $(‘Split Out’).last().json.sections }}
{{ $(‘Split Out’).all()[$itemIndex].json.sections }}
and so on, but nothing seemed to work. The Elaborate always picks up the output of the first item’s run.

Please share your workflow

Is there a way to differentiate between runs? If so, how?

Information on your n8n setup

Maybe your inner loop is grabbing data from the first run instead of the current one? It could be because the “Loop Over Items #2” node isn’t picking up the fresh data from each new iteration of your outer loop. It will just use that first batch of data again" even when you’re on a completely different item.

Have you tried using the run index variable? Something like {{ $runIndex }} might help the system understand which iteration it’s on. Maybe instead of using .last() (which only grabs the most recent output regardless of which iteration you’re on), you could try something like {{ $('Split Out')[$runIndex].json.sections }} to specifically target the current run’s data.

Yes, tried {{ $(‘Split Out’)[$runIndex].json.sections }} as well.

Doesn’t work, in fact with [$runIndex] doesn’t even pick up the output of the first run.

Any other tips on this from anyone?

Nested loops are tricky indeed.
One solution option is to put the nested loop into a sub-workflow and call it from the outer loop. You can even keep the sub-workflow on the same canvas.

If this proposal resolves your issue, please mark this post as a :white_check_mark: Solution.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.