Loop Node references seem broken

Describe the problem/error/question

The Loop Node’s references are not working as per the current syntax ( $('Loop')... ).
They are working only for $node["Loop"]...

Please share your workflow

Share the output returned by the last node

Output of the Set node:

Information on your n8n setup

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

This syntax works:

{{  $('Loop Over Items').item.json }}

@shrey-42 , in your example, the Loop node is not used in intended way. Hence, the result you get.

Try this instead:

Hi @ihortom , could you try to run my wf using your approach?

PS: the provided wf is for demo purpose only, and there’s no difference in the output either way.

I ran it in v1.17.1. Here’s the output

[
  {
    "loop_all": [
      {
        "json": {
          "id": "23423532",
          "name": "Jay Gatsby",
          "email": "[email protected]",
          "notes": "Keeps asking about a green light??",
          "country": "US",
          "created": "1925-04-10"
        },
        "pairedItem": {
          "sourceOverwrite": {
            "previousNode": "No Operation, do nothing"
          },
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423533",
          "name": "José Arcadio Buendía",
          "email": "[email protected]",
          "notes": "Lots of people named after him. Very confusing",
          "country": "CO",
          "created": "1967-05-05"
        },
        "pairedItem": {
          "sourceOverwrite": {
            "previousNode": "No Operation, do nothing",
            "previousNodeRun": 1
          },
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423534",
          "name": "Max Sendak",
          "email": "[email protected]",
          "notes": "Keeps rolling his terrible eyes",
          "country": "US",
          "created": "1963-04-09"
        },
        "pairedItem": {
          "sourceOverwrite": {
            "previousNode": "No Operation, do nothing",
            "previousNodeRun": 2
          },
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423535",
          "name": "Zaphod Beeblebrox",
          "email": "[email protected]",
          "notes": "Felt like I was talking to more than one person",
          "country": null,
          "created": "1979-10-12"
        },
        "pairedItem": {
          "sourceOverwrite": {
            "previousNode": "No Operation, do nothing",
            "previousNodeRun": 3
          },
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423536",
          "name": "Edmund Pevensie",
          "email": "[email protected]",
          "notes": "Passionate sailor",
          "country": "UK",
          "created": "1950-10-16"
        },
        "pairedItem": {
          "sourceOverwrite": {
            "previousNode": "No Operation, do nothing",
            "previousNodeRun": 4
          },
          "item": 0
        }
      }
    ],
    "loop_first": {
      "json": {
        "id": "23423532",
        "name": "Jay Gatsby",
        "email": "[email protected]",
        "notes": "Keeps asking about a green light??",
        "country": "US",
        "created": "1925-04-10"
      },
      "pairedItem": {
        "sourceOverwrite": {
          "previousNode": "No Operation, do nothing"
        },
        "item": 0
      }
    },
    "data_all": [
      {
        "json": {
          "id": "23423532",
          "name": "Jay Gatsby",
          "email": "[email protected]",
          "notes": "Keeps asking about a green light??",
          "country": "US",
          "created": "1925-04-10"
        },
        "pairedItem": {
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423533",
          "name": "José Arcadio Buendía",
          "email": "[email protected]",
          "notes": "Lots of people named after him. Very confusing",
          "country": "CO",
          "created": "1967-05-05"
        },
        "pairedItem": {
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423534",
          "name": "Max Sendak",
          "email": "[email protected]",
          "notes": "Keeps rolling his terrible eyes",
          "country": "US",
          "created": "1963-04-09"
        },
        "pairedItem": {
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423535",
          "name": "Zaphod Beeblebrox",
          "email": "[email protected]",
          "notes": "Felt like I was talking to more than one person",
          "country": null,
          "created": "1979-10-12"
        },
        "pairedItem": {
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423536",
          "name": "Edmund Pevensie",
          "email": "[email protected]",
          "notes": "Passionate sailor",
          "country": "UK",
          "created": "1950-10-16"
        },
        "pairedItem": {
          "item": 0
        }
      }
    ],
    "data_first": {
      "json": {
        "id": "23423532",
        "name": "Jay Gatsby",
        "email": "[email protected]",
        "notes": "Keeps asking about a green light??",
        "country": "US",
        "created": "1925-04-10"
      },
      "pairedItem": {
        "item": 0
      }
    }
  },
  {
    "loop_all": [
      {
        "json": {
          "id": "23423532",
          "name": "Jay Gatsby",
          "email": "[email protected]",
          "notes": "Keeps asking about a green light??",
          "country": "US",
          "created": "1925-04-10"
        },
        "pairedItem": {
          "sourceOverwrite": {
            "previousNode": "No Operation, do nothing"
          },
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423533",
          "name": "José Arcadio Buendía",
          "email": "[email protected]",
          "notes": "Lots of people named after him. Very confusing",
          "country": "CO",
          "created": "1967-05-05"
        },
        "pairedItem": {
          "sourceOverwrite": {
            "previousNode": "No Operation, do nothing",
            "previousNodeRun": 1
          },
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423534",
          "name": "Max Sendak",
          "email": "[email protected]",
          "notes": "Keeps rolling his terrible eyes",
          "country": "US",
          "created": "1963-04-09"
        },
        "pairedItem": {
          "sourceOverwrite": {
            "previousNode": "No Operation, do nothing",
            "previousNodeRun": 2
          },
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423535",
          "name": "Zaphod Beeblebrox",
          "email": "[email protected]",
          "notes": "Felt like I was talking to more than one person",
          "country": null,
          "created": "1979-10-12"
        },
        "pairedItem": {
          "sourceOverwrite": {
            "previousNode": "No Operation, do nothing",
            "previousNodeRun": 3
          },
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423536",
          "name": "Edmund Pevensie",
          "email": "[email protected]",
          "notes": "Passionate sailor",
          "country": "UK",
          "created": "1950-10-16"
        },
        "pairedItem": {
          "sourceOverwrite": {
            "previousNode": "No Operation, do nothing",
            "previousNodeRun": 4
          },
          "item": 0
        }
      }
    ],
    "loop_first": {
      "json": {
        "id": "23423532",
        "name": "Jay Gatsby",
        "email": "[email protected]",
        "notes": "Keeps asking about a green light??",
        "country": "US",
        "created": "1925-04-10"
      },
      "pairedItem": {
        "sourceOverwrite": {
          "previousNode": "No Operation, do nothing"
        },
        "item": 0
      }
    },
    "data_all": [
      {
        "json": {
          "id": "23423532",
          "name": "Jay Gatsby",
          "email": "[email protected]",
          "notes": "Keeps asking about a green light??",
          "country": "US",
          "created": "1925-04-10"
        },
        "pairedItem": {
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423533",
          "name": "José Arcadio Buendía",
          "email": "[email protected]",
          "notes": "Lots of people named after him. Very confusing",
          "country": "CO",
          "created": "1967-05-05"
        },
        "pairedItem": {
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423534",
          "name": "Max Sendak",
          "email": "[email protected]",
          "notes": "Keeps rolling his terrible eyes",
          "country": "US",
          "created": "1963-04-09"
        },
        "pairedItem": {
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423535",
          "name": "Zaphod Beeblebrox",
          "email": "[email protected]",
          "notes": "Felt like I was talking to more than one person",
          "country": null,
          "created": "1979-10-12"
        },
        "pairedItem": {
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423536",
          "name": "Edmund Pevensie",
          "email": "[email protected]",
          "notes": "Passionate sailor",
          "country": "UK",
          "created": "1950-10-16"
        },
        "pairedItem": {
          "item": 0
        }
      }
    ],
    "data_first": {
      "json": {
        "id": "23423532",
        "name": "Jay Gatsby",
        "email": "[email protected]",
        "notes": "Keeps asking about a green light??",
        "country": "US",
        "created": "1925-04-10"
      },
      "pairedItem": {
        "item": 0
      }
    }
  },
  {
    "loop_all": [
      {
        "json": {
          "id": "23423532",
          "name": "Jay Gatsby",
          "email": "[email protected]",
          "notes": "Keeps asking about a green light??",
          "country": "US",
          "created": "1925-04-10"
        },
        "pairedItem": {
          "sourceOverwrite": {
            "previousNode": "No Operation, do nothing"
          },
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423533",
          "name": "José Arcadio Buendía",
          "email": "[email protected]",
          "notes": "Lots of people named after him. Very confusing",
          "country": "CO",
          "created": "1967-05-05"
        },
        "pairedItem": {
          "sourceOverwrite": {
            "previousNode": "No Operation, do nothing",
            "previousNodeRun": 1
          },
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423534",
          "name": "Max Sendak",
          "email": "[email protected]",
          "notes": "Keeps rolling his terrible eyes",
          "country": "US",
          "created": "1963-04-09"
        },
        "pairedItem": {
          "sourceOverwrite": {
            "previousNode": "No Operation, do nothing",
            "previousNodeRun": 2
          },
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423535",
          "name": "Zaphod Beeblebrox",
          "email": "[email protected]",
          "notes": "Felt like I was talking to more than one person",
          "country": null,
          "created": "1979-10-12"
        },
        "pairedItem": {
          "sourceOverwrite": {
            "previousNode": "No Operation, do nothing",
            "previousNodeRun": 3
          },
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423536",
          "name": "Edmund Pevensie",
          "email": "[email protected]",
          "notes": "Passionate sailor",
          "country": "UK",
          "created": "1950-10-16"
        },
        "pairedItem": {
          "sourceOverwrite": {
            "previousNode": "No Operation, do nothing",
            "previousNodeRun": 4
          },
          "item": 0
        }
      }
    ],
    "loop_first": {
      "json": {
        "id": "23423532",
        "name": "Jay Gatsby",
        "email": "[email protected]",
        "notes": "Keeps asking about a green light??",
        "country": "US",
        "created": "1925-04-10"
      },
      "pairedItem": {
        "sourceOverwrite": {
          "previousNode": "No Operation, do nothing"
        },
        "item": 0
      }
    },
    "data_all": [
      {
        "json": {
          "id": "23423532",
          "name": "Jay Gatsby",
          "email": "[email protected]",
          "notes": "Keeps asking about a green light??",
          "country": "US",
          "created": "1925-04-10"
        },
        "pairedItem": {
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423533",
          "name": "José Arcadio Buendía",
          "email": "[email protected]",
          "notes": "Lots of people named after him. Very confusing",
          "country": "CO",
          "created": "1967-05-05"
        },
        "pairedItem": {
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423534",
          "name": "Max Sendak",
          "email": "[email protected]",
          "notes": "Keeps rolling his terrible eyes",
          "country": "US",
          "created": "1963-04-09"
        },
        "pairedItem": {
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423535",
          "name": "Zaphod Beeblebrox",
          "email": "[email protected]",
          "notes": "Felt like I was talking to more than one person",
          "country": null,
          "created": "1979-10-12"
        },
        "pairedItem": {
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423536",
          "name": "Edmund Pevensie",
          "email": "[email protected]",
          "notes": "Passionate sailor",
          "country": "UK",
          "created": "1950-10-16"
        },
        "pairedItem": {
          "item": 0
        }
      }
    ],
    "data_first": {
      "json": {
        "id": "23423532",
        "name": "Jay Gatsby",
        "email": "[email protected]",
        "notes": "Keeps asking about a green light??",
        "country": "US",
        "created": "1925-04-10"
      },
      "pairedItem": {
        "item": 0
      }
    }
  },
  {
    "loop_all": [
      {
        "json": {
          "id": "23423532",
          "name": "Jay Gatsby",
          "email": "[email protected]",
          "notes": "Keeps asking about a green light??",
          "country": "US",
          "created": "1925-04-10"
        },
        "pairedItem": {
          "sourceOverwrite": {
            "previousNode": "No Operation, do nothing"
          },
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423533",
          "name": "José Arcadio Buendía",
          "email": "[email protected]",
          "notes": "Lots of people named after him. Very confusing",
          "country": "CO",
          "created": "1967-05-05"
        },
        "pairedItem": {
          "sourceOverwrite": {
            "previousNode": "No Operation, do nothing",
            "previousNodeRun": 1
          },
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423534",
          "name": "Max Sendak",
          "email": "[email protected]",
          "notes": "Keeps rolling his terrible eyes",
          "country": "US",
          "created": "1963-04-09"
        },
        "pairedItem": {
          "sourceOverwrite": {
            "previousNode": "No Operation, do nothing",
            "previousNodeRun": 2
          },
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423535",
          "name": "Zaphod Beeblebrox",
          "email": "[email protected]",
          "notes": "Felt like I was talking to more than one person",
          "country": null,
          "created": "1979-10-12"
        },
        "pairedItem": {
          "sourceOverwrite": {
            "previousNode": "No Operation, do nothing",
            "previousNodeRun": 3
          },
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423536",
          "name": "Edmund Pevensie",
          "email": "[email protected]",
          "notes": "Passionate sailor",
          "country": "UK",
          "created": "1950-10-16"
        },
        "pairedItem": {
          "sourceOverwrite": {
            "previousNode": "No Operation, do nothing",
            "previousNodeRun": 4
          },
          "item": 0
        }
      }
    ],
    "loop_first": {
      "json": {
        "id": "23423532",
        "name": "Jay Gatsby",
        "email": "[email protected]",
        "notes": "Keeps asking about a green light??",
        "country": "US",
        "created": "1925-04-10"
      },
      "pairedItem": {
        "sourceOverwrite": {
          "previousNode": "No Operation, do nothing"
        },
        "item": 0
      }
    },
    "data_all": [
      {
        "json": {
          "id": "23423532",
          "name": "Jay Gatsby",
          "email": "[email protected]",
          "notes": "Keeps asking about a green light??",
          "country": "US",
          "created": "1925-04-10"
        },
        "pairedItem": {
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423533",
          "name": "José Arcadio Buendía",
          "email": "[email protected]",
          "notes": "Lots of people named after him. Very confusing",
          "country": "CO",
          "created": "1967-05-05"
        },
        "pairedItem": {
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423534",
          "name": "Max Sendak",
          "email": "[email protected]",
          "notes": "Keeps rolling his terrible eyes",
          "country": "US",
          "created": "1963-04-09"
        },
        "pairedItem": {
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423535",
          "name": "Zaphod Beeblebrox",
          "email": "[email protected]",
          "notes": "Felt like I was talking to more than one person",
          "country": null,
          "created": "1979-10-12"
        },
        "pairedItem": {
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423536",
          "name": "Edmund Pevensie",
          "email": "[email protected]",
          "notes": "Passionate sailor",
          "country": "UK",
          "created": "1950-10-16"
        },
        "pairedItem": {
          "item": 0
        }
      }
    ],
    "data_first": {
      "json": {
        "id": "23423532",
        "name": "Jay Gatsby",
        "email": "[email protected]",
        "notes": "Keeps asking about a green light??",
        "country": "US",
        "created": "1925-04-10"
      },
      "pairedItem": {
        "item": 0
      }
    }
  },
  {
    "loop_all": [
      {
        "json": {
          "id": "23423532",
          "name": "Jay Gatsby",
          "email": "[email protected]",
          "notes": "Keeps asking about a green light??",
          "country": "US",
          "created": "1925-04-10"
        },
        "pairedItem": {
          "sourceOverwrite": {
            "previousNode": "No Operation, do nothing"
          },
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423533",
          "name": "José Arcadio Buendía",
          "email": "[email protected]",
          "notes": "Lots of people named after him. Very confusing",
          "country": "CO",
          "created": "1967-05-05"
        },
        "pairedItem": {
          "sourceOverwrite": {
            "previousNode": "No Operation, do nothing",
            "previousNodeRun": 1
          },
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423534",
          "name": "Max Sendak",
          "email": "[email protected]",
          "notes": "Keeps rolling his terrible eyes",
          "country": "US",
          "created": "1963-04-09"
        },
        "pairedItem": {
          "sourceOverwrite": {
            "previousNode": "No Operation, do nothing",
            "previousNodeRun": 2
          },
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423535",
          "name": "Zaphod Beeblebrox",
          "email": "[email protected]",
          "notes": "Felt like I was talking to more than one person",
          "country": null,
          "created": "1979-10-12"
        },
        "pairedItem": {
          "sourceOverwrite": {
            "previousNode": "No Operation, do nothing",
            "previousNodeRun": 3
          },
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423536",
          "name": "Edmund Pevensie",
          "email": "[email protected]",
          "notes": "Passionate sailor",
          "country": "UK",
          "created": "1950-10-16"
        },
        "pairedItem": {
          "sourceOverwrite": {
            "previousNode": "No Operation, do nothing",
            "previousNodeRun": 4
          },
          "item": 0
        }
      }
    ],
    "loop_first": {
      "json": {
        "id": "23423532",
        "name": "Jay Gatsby",
        "email": "[email protected]",
        "notes": "Keeps asking about a green light??",
        "country": "US",
        "created": "1925-04-10"
      },
      "pairedItem": {
        "sourceOverwrite": {
          "previousNode": "No Operation, do nothing"
        },
        "item": 0
      }
    },
    "data_all": [
      {
        "json": {
          "id": "23423532",
          "name": "Jay Gatsby",
          "email": "[email protected]",
          "notes": "Keeps asking about a green light??",
          "country": "US",
          "created": "1925-04-10"
        },
        "pairedItem": {
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423533",
          "name": "José Arcadio Buendía",
          "email": "[email protected]",
          "notes": "Lots of people named after him. Very confusing",
          "country": "CO",
          "created": "1967-05-05"
        },
        "pairedItem": {
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423534",
          "name": "Max Sendak",
          "email": "[email protected]",
          "notes": "Keeps rolling his terrible eyes",
          "country": "US",
          "created": "1963-04-09"
        },
        "pairedItem": {
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423535",
          "name": "Zaphod Beeblebrox",
          "email": "[email protected]",
          "notes": "Felt like I was talking to more than one person",
          "country": null,
          "created": "1979-10-12"
        },
        "pairedItem": {
          "item": 0
        }
      },
      {
        "json": {
          "id": "23423536",
          "name": "Edmund Pevensie",
          "email": "[email protected]",
          "notes": "Passionate sailor",
          "country": "UK",
          "created": "1950-10-16"
        },
        "pairedItem": {
          "item": 0
        }
      }
    ],
    "data_first": {
      "json": {
        "id": "23423532",
        "name": "Jay Gatsby",
        "email": "[email protected]",
        "notes": "Keeps asking about a green light??",
        "country": "US",
        "created": "1925-04-10"
      },
      "pairedItem": {
        "item": 0
      }
    }
  }
]

The ‘correct’ way to run using your approach is -

which yields the same result as earlier.

@shrey-42 , you keep getting that result because it is expected in both of your configurations. Can you explain what is your goal here? So far I do not see any problem. The “Loop” node works as per design. It sounds like your expectations do not match the design. Am I missing something?

This suggests that the output of the current run should be available via $("Loop node).all() & $("Loop node).first()

Right, so it is not an issue with Loop node as such (again, it works as expected) but rather with the methods allowing to get the values of the previous nodes in the chain.

Looks like there is a misunderstanding of how to use those methods. Let’s concentration on that. What method you think does not work and what you expect to see?

Going ahead I can tell that its usage (syntax) depends on the node you are referring to. You need to consider how many items in the list it produces, how many outputs that node has, and how many iterations it ran. All this dictates how to use the node methods.

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