Set node behavior when fan out to multiple items

Describe the issue/error/question

Hi I’m running into a somewhat counter-intuitive behavior when using a single “Set” node, followed by fan out to multiple items.

When I set a value (foo: bar in the example) in a “Set” node and some later node (in this example a code node) fans out to a multiple items, only first item will be able to see the value I set.

For example: look at the markdown node. Here is what it produces:

20230311_16h44m33s_grim

So “bar” is visible when running markdown for the first item, but not for the 2nd and 3rd.

I would expect all items to see whatever I’ve set in a “Set” node before, because why wouldn’t they? Documentation doesn’t give any clues about this behavior.

There is a workaround with running a map node after fanout and assigning every item a copy of a value, which solves the problem, but still I would like to understand the logic behind the current behavior.

What is the error message (if any)?

None

Please share the workflow

Share the output returned by the last node

[
  {
    "id": 1,
    "data": "<p>1,  bar</p>"
  },
  {
    "id": 2,
    "data": "<p>2,  </p>"
  },
  {
    "id": 3,
    "data": "<p>3,  </p>"
  }
]

Information on your n8n setup

  • n8n version: 0.217.2
  • Database you’re using (default: SQLite): sqlite
  • Running n8n with the execution process [own(default), main]: own
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: Docker

Hey @dyd0s3r,

Welcome to the community :tada:

This is likely to be down to how we loop data in nodes, If you have one item coming out of a node then 3 items and you use $node.x.json.y we will assume 3 items coming out of the set node so we will do item 1, 2 then 3 but because only the first exists you get an item.

We do have pairedItems which should make this a bit better but when a code node is mixed in it cause the same thing as we can’t always work out the item to match the output to. The best thing to do in cases like this is to use $('node name').first().json.y which will then result in the first item always being used.

1 Like

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