Set node only setting first row

Hi guys!

I’m having a bit of trouble with a set node.
I’m using the notion node to get a database name, then I pass that name to a set node under a text variable.

My issue is that I’m only getting that variable set on the first row. I didn’t find anything related to this on the documentation nor any posts here.

Can you please help me out?

Hi @Daniel_Barra, hope you’re having a good day? Most nodes run once for each item, so it sounds like for your second (and subsequent items) there is no item. In that case could try an expression like {{$items("My Node")[0].json["foo"]}} where My Node is your Notion node and foo is the field with the database name.

The $items() method would always refer to all items of the current or previous nodes, so by using [0] you reference the very first item regardless of how many items you have.

Example Workflow

(This uses an HTTP Request and an Item Lists node to get some example items.)

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "foo",
              "value": "bar"
            }
          ]
        },
        "options": {}
      },
      "name": "Set Single Value",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "url": "https://reqres.in/api/users/",
        "options": {}
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "fieldToSplitOut": "data",
        "options": {}
      },
      "name": "Item Lists",
      "type": "n8n-nodes-base.itemLists",
      "typeVersion": 1,
      "position": [
        850,
        300
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "mySingleValue",
              "value": "={{$items(\"Set Single Value\")[0].json[\"foo\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Update Each Item",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        1050,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Set Single Value",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Single Value": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Item Lists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Item Lists": {
      "main": [
        [
          {
            "node": "Update Each Item",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Alternatively, if your Set node following the Notion node afterwards only returns one item, you could use the Merge node in Multiplex mode. This would also add the single field to each item:

Example Workflow
{
  "nodes": [
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "foo",
              "value": "bar"
            }
          ]
        },
        "options": {}
      },
      "name": "Set Single Value",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "url": "https://reqres.in/api/users/",
        "options": {}
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        650,
        200
      ]
    },
    {
      "parameters": {
        "fieldToSplitOut": "data",
        "options": {}
      },
      "name": "Item Lists",
      "type": "n8n-nodes-base.itemLists",
      "typeVersion": 1,
      "position": [
        850,
        200
      ]
    },
    {
      "parameters": {
        "mode": "multiplex"
      },
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        1050,
        300
      ]
    }
  ],
  "connections": {
    "Set Single Value": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Item Lists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Item Lists": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Hope this gives you some pointers! Let me know if I misunderstood you here or you have any further questions on this.

Thank you so much @MutedJam !

It worked like a charm.

I’ll explain below exactly what I did.

image

This is the final structure of that part of the workflow.
On the SET node, I had to activate the option Execute Once and the Keep Only Set options.


Then using multiplex option of the MERGE node, it worked perfectly.

Once again, thanks for the help!

1 Like

Awesome, glad to hear that. Thanks so much for confirming and sharing your approach!