Nested looping doesn't seem to go in the correct order

Describe the problem/error/question

When running nested loops, the order of operations doesn’t seem to work as expected. I’m sure it’s just me not understanding the underlying functionality of the looping mechanism so I’d love some help.

Here’s what I’m trying to do:

  1. Fetch all campaigns from airtable
  2. For each campaign, find the associated ad groups from another table
  3. For each ad group, fetch all of the associated ads

At each step I want to put that current info to a Google Doc so that I can form a simple text doc like this:

Campaign A
Ad Group A
Ad A
Ad B
Ad Group B
Ad A
Ad B

Campaign B

etc

Please share your workflow

Output

Although the workflow runs without error, the order is all messed up. It’s pushing all of the campaigns first then pushing in all of the ad groups, then finally the ads. Instead of correctly nesting them

Information on your n8n setup

  • n8n version: 1.41.1
  • Database (default: SQLite): default
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): docker
  • Operating system:

hello @trentwaskey

Nested loops won’t work :slight_smile:

You have to move the inner loop functionality into the separate workflow and execute it for every item of the outer loop

1 Like

@barn4k wow, I feel stupid for spending a day on this and not thinking to use sub-workflows. This works perfectly, thank you!

1 Like

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