How to access current data of an iteration later in the workflow?

Hello everybody, I have an issue while iterating on datas from Airtable and I can’t figure out what I’m doing wrong (or if it’s a bug). More details below but I’ve also made a quick screencast to explain everything : N8N Question - how to access previous data - YouTube

Describe the issue/error/question

I have a workflow that basically makes a API request for every records of an Airtable table. This part is working fine. After that depending on the request responde code (200 or 404), I have two actions : one is deleting the record and the other is updating the record. I need the matching record ID for both actions.

I can’t seem to access the record ID at this point of the workflow. I’m probably doing something wrong but I can’t figure it out.

I do get a record ID but it’s not the one matching the iteration. Kinda hard to explain that’s why I made the screencast.

It always gives me the the record ID sequentially but it’s not matching the execution. I’ve spent a lot of time on this and it might be a bug I don’t know. Help will be appreciated :slight_smile:

The flow :

How I’m trying to get the record ID :

Information on your n8n setup

  • n8n version: 0.153.0
  • Database you’re using (default: SQLite) : SQLite

Welcome to the community @AlexKovax

Add a set node after the HTTP node. With the Set node add the record id from Airtable using an expression. That way all the data you need it’s going to be passed through the IF node, meaning you are not gonna need to use expressions in the Set nodes after the IF to reference the record id. Check the example workflow below.

The issue you are having it’s expected. The set node in the false branch only receives as inputs two items but the Airtable node you are referencing in the set node returns 10 items. If they both had the same amount of items this would work.

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        -120,
        240
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      id: 1\n    }\n  },\n    {\n    json: {\n      id: 2\n    }\n  },\n      {\n    json: {\n      id: 3\n    }\n  }\n]"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        120,
        240
      ],
      "notesInFlow": true,
      "notes": "mockup airtable"
    },
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      data: 'hola'\n    }\n  },\n    {\n    json: {\n      data: 'hola2'\n    }\n  },\n      {\n    json: {\n      data: 'hola3'\n    }\n  }\n]"
      },
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        340,
        240
      ],
      "notesInFlow": true,
      "notes": "HTTP mockup"
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "id",
              "value": "={{$node[\"Function\"].json[\"id\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        540,
        240
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [],
          "number": [
            {
              "value1": "={{$node[\"Set\"].json[\"id\"]}}",
              "operation": "equal",
              "value2": 1
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        760,
        240
      ]
    },
    {
      "parameters": {},
      "name": "NoOp",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        980,
        40
      ]
    },
    {
      "parameters": {},
      "name": "NoOp1",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        980,
        320
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "Function1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function1": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "NoOp",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "NoOp1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
2 Likes

Thank you so much for this @RicardoE105! :pray:
It’s working fine now, and I’m starting to understand n8n more clearly, yay!

1 Like

Great that it worked. Have fun. Let us know if you have further questions.