Function with Two loops


How can i make a function with a loop inside another loop - (i.e. the items come from two different nodes)

  • The first loop I want to do (line 16) does not work

ERROR: Cannot read property ‘Get InvoiceItemLines’ of undefined [Line 16].

  • The second loop I want to do on price (knowing that the items of this item come from another node)


Thanks for your help.

Hey @Hasnaa_SOUIBA, that’s more of a general JavaScript question seeing you want to use a function tbh. Here’s a quick example showing a loop inside a loop using n8n’s Function node:

Example Workflow

This will loop through the items returned by the first node (a few names) and then for each of these items loop through all items returned by the second node (a bunch of activities):

Is this what you had in mind?

Thanks for your help @MutedJam

I’m going to test this - (I just updated my post with the code)