Merge with one input from loop node and one input from code node

Describe the problem/error/question

Hi there! I’m pretty new to n8n but already enjoying working with it. What I want to do is to merge data from 2 different inputs: one input comes from a “loop over items” node (input 1) and the other input is static (fetched once and never changes through cycles) comes from a code node (input 2). I want to merge input 2 with input 1 on every loop cycle. The problem that I’m having is that the merge is done only for the first cycle, and the other cycles output the data just from input 1, without merging. I want to solve this issue.

I suspect that this is due to the nature of how the merge node works: it waits for the 2 inputs to be available. This is done for the first cycle, but for the rest of the cycles, it seems that the merge node detects both inputs are already available, and does the merge without considering input 2. But this is just what I think.

What is the error message (if any)?

This is the output for the first cycle of the loop. As you can see, the data object (input 2) is appended to the output.

And this is the output from the second cycle. Only the data from input 1 is showing in the output, but no data object in it.

Please share your workflow

Sharing the part of the flow were I’m having problems

Information on your n8n setup

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

hey @Miguel_Chirinos welcome to n8n community!

can I ask what issue it causes?
does it not allows to access data from codenode?
Or what you want to do here?

I think you could merge the inputs before looping… Something like

Hi @moosa ! Thanks for replying. I’ll give more details. The problem that I’m having is that the code node output is only been merged on the first loop cycle. The output images show it clearly, but I can clarify. For example, I have this data that is run through the loop node (input 1 of the merge node)

[
  {"name": "Joe"},
  {"name": "Jane"},
  {"name": "Paul"}
]

And this data in the code node output (input 2 of the merge node)

{"data": "some_data"}

I expect that the merge loop appends the data of input 2 with input 1 on each of the array runs, so that I get different outputs on each run like this:

{ "name": "Joe"}, {"data": "some_data"} // run 1
{ "name": "Jane"}, {"data": "some_data"} // run 2
{ "name": "Paul"}, {"data": "some_data"} // run 3

But instead, I’m getting the data of input 2 appended only on the first run, and the outputs look like this

{ "name": "Joe"}, {"data": "some_data"} // run 1
{ "name": "Jane"} // run 2
{ "name": "Paul"} // run 3

I hope this clarifies the problem

@Miguel_Chirinos I think this solution from @jabbson could work for your desired output,
did you tried merging before loop?

Thanks @jabbson ! This solved the issue. Also, instead of appending, I ended up using Combine (as shown in your solution + All Possible Combinations). Thanks for the help!