How to solve "Can't determine what item to use"?

I’ve recently learned from this topic that using branches, loops or generating new items can cause n8n to loose reference of the items from previous nodes.

Following on this topic I would like to know more about how to mitigate or prevent this issue, by learning some good practices, because just using first() and last() is not ideal most of the time.

I’ve started using the Merge node more often. But I have a feeling there might be a more effective method.

From all the documentation listed below, two things I couldn’t understand were:

The first method I don’t understand at all. But I think I got the second method… It solves the problem by simply creating a JSON parameter containing the item index, right?

Documentation I’ve read:

Information on your n8n setup

  • n8n version: 1.71.3
  • Database (default: SQLite): SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): docker
  • Operating system: Ubuntu 24.04
1 Like

Hey @solomon ,

This is equivalent to $("<node-name>").item. The difference is, you cannot use the reference .item in Code node. Instead, you would use .itemMatching().

The n8n nodes add pairedItem for you (it’s up to the node developer to ensure it is done, see Item linking for node creators | n8n Docs). What this document implies is, you can override pairedItem yourself for all the output items making sure the ouput item links to the input item of your choosing. Though, it is unlikely you would have to do it yourself.

2 Likes

Thank you @ihortom

But what would be some good practices for preventing the workflow to lose reference?

Is using the Merge node actually a good strategy? I thought I was using a workaround.

There is nothing wrong with using Merge and it could be the best aproach to your use case. It really depends on what you are trying to achieve. n8n provides different means and it is up to you as a workflow builder to use the right tool/technique/aproach for the task.

n8n is more “low-code” rather than “no-code” which allows for greater flexibility for technically minded people.

2 Likes

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