Fields showing undefined just in one node

Describe the problem/error/question

Fields changing to undefined when running, but show data prior to execution [sometimes]. Several previous nodes reference the same data, but only the last step is doing this. It’ll work if I change .item to .first(), but there’s only 1 item. Looking for clarification on what’s different here.

With all the previous nodes run, this is what the last step looks like prior to execution. Sometimes it will say undefined the entire time though. I don’t know why sometimes re-executing the previous steps will make the data available, but other times not.

And when I go to execute it (in editor as test, or live), it turns into this:

But if I go to the previous node, it’s referencing the same data just fine

The expressions there are just from dragging the fields in. Now, if I replace item in the expression with first(), it works. I do not understand why though, as I do not have to do that in previous nodes. And there’s only 1 item being passed through. The other branch, which references some of the same starting data, works fine with the default expressions. I’ve never had to do that on any of my other workflows either.

Please share your workflow

Some sensitive info in there, but here's a screenshot.  The top branch works fine, calling the same exact sub-workflow as the bottom branch.  Let me know if you want specifics on any nodes in particular.


Information on your n8n setup

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

try this method using item path

good day @flowdan
I’d use .first() here, or better, copy Client_Name and emailSubject into the main item before the branch/merge so the final node can reference $json.customerName / $json.ticketSubject directly.

@flowdan that .item vs .first() thing happens when the node sits after a branch/merge — n8n loses track of which item maps to the upstream node’s output so .item resolves to undefined even though the data exists. easiest permanent fix is to pull those fields into the main item with a Set node right before your final step so you’re just reading $json directly.

drop that Set node right before your final sub-workflow call, add whatever other fields you need, then the last node just reads $json.customer_name instead of reaching back across the branch.

Gotcha. So it’s best practice to (re)Set your active data with first() after any branch/merge and work off that? I’ve got a dozen or so other workflows built so far, with plenty of branching and merging, but I’ve not run into this before. Heck, the top branch of this workflow works just fine with .item. There must be a combination of factors that cause this.

At least I know how to fix it when it does come up now at least, thank you