Loop inside a loop is not working

Hi @Md_Ashickur_Rahman

What you’re seeing is actually expected behavior. Loop Over Items keeps internal state, so when you nest it inside another loop in the same workflow, the inner loop only runs correctly for the first outer iteration.

That’s why Split in Batches works for you , it’s stateless, while Loop Over Items doesn’t handle nesting well.

Here’s what I’d recommend:

The cleanest approach is to move the inner loop logic to a sub-workflow. It keeps things clear and isolated, and you won’t run into state issues.

Alternatively, you could restructure your data so you only need one loop — for example, flatten your invoices and products before looping through them.

If you really need both loops in the same workflow:

There’s an advanced workaround using the Reset option. Go to your inner loop (loop_on_products), open Options → Reset, choose Expression, and try something like:

{{ $prevNode.name === 'get_products_by_invoice' }}

Just replace 'get_products_by_invoice' with whatever node actually feeds products into your inner loop.

What this does is tell n8n: “Hey, when new items arrive from that node, reset the inner loop and start fresh. But when the loop continues on its own Continue branch, don’t reset — otherwise you’ll get stuck in an infinite loop.”

This is a known workaround in the community (sometimes called the “classic nested loop fix”), but honestly, the sub-workflow approach tends to be cleaner and way less prone to weird bugs down the road.

Reference:
[Nested loops; Loop on loop; Loop inside loop]
[Loops/Sub-loop; Split in batch nested]