I have been using N8N for some time, self hosted and I have several workflows setup and working.
I hope this isn’t too dumb of a question but can someone help me understand loops. Specifically, I have a “order” data structure, with 1 or more line items. Pretty standard.
I need to do processing for each line item. In my case, for each line item I need to look at the product ID of the line item and then do some processing. In this case the “processing node” is a switch statement.
I tried referencing the product ID in the routing rules of the switch statement but it references an individual array item and only processes that one
In your example, I see there are 3 items coming from the first step. So the loop steps runs 3 times.
In my data structure, I have 1 order and inside of that are 3 line items. So the next step only seem to see 1 item because it looks at the outer most data structure. How do I point it to the inside line items array?
I used a set node to pull out the line items from 3 nodes previous. The line items were still nested 3 layers deep as in the original data structure.
Then I used split out on that output to make the items at the top level. Then I get multiple items coming out and the next node runs once per item.
Does this sound like the way you are supposed to do it? I couldnt find a way to reference the original nested list from 3 nodes back in split out, so I had to use the set node before it
I really like and appreciate N8N, I use it every few days in my work.
I say with love and respect that I think N8N is doing a poor job of explaining loops in the documentation. The same few examples and tag lines are usually quoted. The loop system is no doubt elegant but it has been very hard to understand how they work.
I wouldnt say I understand but I have fumbled through enough to make my code work.