I have a workflow with a nested loop structure where:
The outer loop processes different client types and generates unique content for each
The inner loop should process this content through translations for different languages
However, when the outer loop moves to its second iteration, the inner language loop fails to process the languages, seemingly thinking it has already processed these items.
What I’ve Tried
Adding unique identifiers to languages using expressions:
{{ $('On form submission').item.json.Languages.map(lang => lang + '_' + $now()) }}
And then cleaning them up when referenced:
{{ $('Loop Over Items').item.json.Languages.split('_')[0] }}
Structuring the language data to include unique combinations of client type and language
However, even with these attempts at making each iteration’s data unique, the inner loop still fails to process languages on the second iteration of the outer loop.
Expected Behavior
First iteration: Process client type 1’s content through all languages
Second iteration: Process client type 2’s content through all languages
And so on…
Actual Behavior
First iteration: Works correctly
Second iteration: Inner loop doesn’t process the languages, seems to think they’re already processed
How can I structure this workflow so that the inner language loop properly processes all languages for each iteration of the outer client type loop? Is there a different approach to handling nested loops that would work better for this use case?
Any help or suggestions would be greatly appreciated!
That’s because you can’t use nested loops via the Loop Node, you should move the inner loop into the sub workflow. Or you can move both loops into sub workflows (e.g. main WF > sub WF as an outer loop > sub-sub WF as an inner loop)
Last question: what is the proper way to do this in my case? I had a “Split Out” node before the Loop node, and it made sense. Here, it seems like I need to have a “Set” or “Code” node before the “Execution Workflow” to pass on the data, but how would it know which items to loop over if I can’t have a “Split Out” before the Loop node?
Place a Code/Edit fields node after the Split Out node and add additional fields which you may need for the sub workflow to do it’s work.
Most likely you will need to specify variables from other nodes with syntax $('nodename').last().json.variableName or $('nodename').first().json.variableName.
Because the syntax $('nodename').item.json.variableName won’t work if the number of items on the choosen node doesn’t match with the number of items of the target ‘nodename’ node (or if any node inbetween has a different number of items)