Please check this demo example. if the first hackernews returns 2 items and than 2nd hackernews return 2 for each I would expect the set modules after the last split in batches to run 4 times each, but it only runs with the first split in batches run. I cannot figure out why. Any ideea?
i was using the hacker news for a mockup here.
Think about the first loop as searching for contacts, and than the second hacker news - searching for invoices for each contact.
First loop takes each contact 1 by 1, than I search for all invoices related to contact 1, than I have the second loop for each invoice related to contact 1.
Practically interating all contacts, getting invoices related to the contact and interating all invocies and applying some logic.
I would expect
Search contacts to return 2 items:
Loop 1-1: Search invoices for Contact1 returns 2 items. Loop 2-1 for 1: Returns 3: 3 items (2 invoices + Done)
Loop 1-2: Second Item Search for Contact2 invoices, Loop 2-2 for 2: returns 3: 3 (2 invoices + done)
You’re mixing loops here which won’t work the way you want it too. So I’d suggest you implement your loop 2 fetching your invoices as a sub-workflow.
Have your main workflow (loop 1) through your contacts, then call the sub-workflow through the Execute Workflow loop. This will also result in improved readability of your workflow, for example:
I understand what you are saying however, are you telling me there is no way to run 1 loop inside another loop?
Using a sub-workflow you can do exactly that and this is the way I’d strongly recommend using. It will keep workflows shorter and thus easier to read and manage.
However, you can also do it without a sub-workflow if you absolutely want. Considering that loops are often used to process larger amounts of data and n8n cloud instances have very limited memory, this is an approach I’d usually avoid to reduce the chance of crashing an n8n cloud instance (using a sub-workflow you can control which data is returned to the parent workflow workflow after each execution, without the sub-workflow all data from your inner loop would be kept in memory for the entire duration of the parent workflow execution).
If you still want to go for it, make sure to upgrade to [email protected] to make sure you have access to the data required for such a construct.