Loop Over Items with external data from the loop

Describe the problem/error/question

I would like to make a loop over a list of items and merge them with data from a node outside the loop
It works for the first loop, but an error occurs for the second loop

My guess is that data from the external loop are consumed, but I don’t know how to reset them

Here is an example of the workflow with the loop

Please share your workflow

Thanks for your help

Information on your n8n setup

  • **n8n version:1.72.1
  • **Database (default: SQLite):PostgreSQL
  • **n8n EXECUTIONS_PROCESS setting (default: own, main):main
  • **Running n8n via (Docker, npm, n8n cloud, desktop app):Docker
  • **Operating system:Debian

Hey @ppcm why would you need Loop node to merge those data sets? Remove the Loop and it will work. If you want to avoid the items with the same values (duplicates) just add Remove Duplicates node after Merge node.

Hello @ihortom
This is a dummy example, of course my data were so simple, they are other ways

If you prefer, here is an example a little bit more complete. The goal is to get data fields, and save them in a separate file

Thanks for your help

Thanks @ppcm , Though I still do not understand why you need the Merge node in the Loop and not before it. Merge the outputs of Code nodes prior to feeding the data to the Loop node. It just a matter of configuring Merge to your needs. Visually I expect to see something like this

Thanks @ihortom for the suggestion, but I don’t understand how the loop is done only on elements in the reference list
With this suggestion, I will have a file for each element in Data list too. Am I wrong?
In fact, I don’t understand how Data list is splited depending of refecences list in your exemple

Thanks for your help

Hey @ppcm , as I stated

It just a matter of configuring Merge to your needs.

The Merge node has many options. You can configure it to output the reference list enriched with data from “Data” node. To make it clearer, consider the options shown below. I’m not sure what data you need to start looping over them to give you definite answer but I believe that Merge node can provide for your use case.

Thanks @ihortom for the information (I knew that :slight_smile: )
But now, with your workflow, how to split data to generate one file per reference (generated in node “List of references”)?

(Merry Christmas :christmas_tree:)

I found a workaround by grouping elements
It consumes more memories, but I didn’t found a better way

What do you think about that?

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