Drag and drop values from previous node not working

I’m having a similar issue to this post, but I can’t find a solution: Using values from previous nodes - cant get data for expression - #5 by Petero

When dragging an input from a node 3 steps back into a field I’m getting “invalid expression”.

Normally in the above I pass the binary to text node to a crypto node to generate a signature hash for authentication, but I removed it just to make it a little more straightforward.

After the Onboard/Offboard switch, I’m calling Jira to make sure no tickets with the same name exists in the system. If the response is empty, I continue the flow. For the last Jira shape, I need to use values from one of the earlier nodes, since no data is passed from the node directly before it. So, I’m attempting to grab data from the Onboard/Offboard Switch after dragging and dropping {{ $('Onboard/Offboard Switch').item.json.fields['First Name'] }}, which returns “invalid expression”.

I have a code node, but it’s only being used to reconstruct the JSON object from the raw body I get from a webhook (which I need to construct the crypto signature). In the following step I’m using a Split Out node, so I feel like adding pairedItem to the code doesn’t really make sense? I’ve tried adding in and I still can’t drag and drop effectively.

Using the legacy syntax works (i.e. {{ $node['Onboard/Offboard Switch'].json.fields['First Name'] }} ), but it only picks up the first item (which makes sense). The webhook can send multiple items which are broken out by the split out node, so I would like to be able to hit the last Jira node with as many times the split node generates.

I placed a manual data insertion node to insert a payload after the split node just to text to see if I could drag and drop in the final Jira Node by bypassing the code node, but I’m having the same issue. Would love to know what I’m doing wrong!

If an example payload is needed, here’s the webhook input data:

{
    "employees": [
        {
            "changedFields": [
                "Status"
            ],
            "fields": {
                "First Name": "test1first",
                "Last Name": "test1last",
                "Department": "Sales",
                "Status": "Inactive",
                "Hire Date": "2022-05-24",
                "Termination Date": "2024-01-17",
                "Work Email": "[email protected]",
                "Home Email": null
            },
            "id": "156"
        },
        {
            "changedFields": [
                "Status"
            ],
            "fields": {
                "First Name": "test2first",
                "Last Name": "test2last",
                "Department": "Sales",
                "Status": "Inactive",
                "Hire Date": "2023-05-08",
                "Termination Date": "2024-01-12",
                "Work Email": "[email protected]",
                "Home Email": "[email protected]"
            },
            "id": "243"
        },
        {
            "changedFields": [
                "Status"
            ],
            "fields": {
                "First Name": "test3first",
                "Last Name": "test3last",
                "Department": "HR/Talent",
                "Status": "Inactive",
                "Hire Date": "2023-12-11",
                "Termination Date": null,
                "Work Email": "[email protected]",
                "Home Email": "[email protected]"
            },
            "id": "279"
        }
    ]
}

And here’s what can be inserted into the manual data node:

[
  {
    "changedFields": [
      "Status"
    ],
    "fields": {
      "First Name": "test_first",
      "Last Name": "test_last",
      "Department": "Sales",
      "Status": "Inactive",
      "Hire Date": "2021-11-16",
      "Termination Date": "2024-01-31",
      "Work Email": "[email protected]",
      "Home Email": null,
      "Country": null
    },
    "id": "136"
  },
  {
    "changedFields": [
      "Status"
    ],
    "fields": {
      "First Name": "test2_first",
      "Last Name": "test2_last",
      "Department": "Exec & Admin",
      "Status": "Inactive",
      "Hire Date": "2023-02-01",
      "Termination Date": "2024-01-31",
      "Work Email": "[email protected]",
      "Home Email": "[email protected]",
      "Country": "United States"
    },
    "id": "223"
  }
]

Information on your n8n setup

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

Would love some help on this!

hi @glances

it’s ok that you see errors with evaluations :sweat_smile:.
It’s because you are using the nodename.item.json reference, which will be evaluated only if the previous node has something to pass to the target node.

See example

And the workflow with data (click on the red text below the workflow to get code)

Apologies, but I’m not understanding your output. I still get “invalid expression” when using {{ $('Onboard/Offboard Switch').item.json.fields['First Name'] }} in the Jira node. I get this error after running a test, not just popping up in the UI before running anything:

It looks like your flow works because the “Check if ticket exists” node is inactive. If you activate that node and test the schema will no longer pass:

I’ve changed the condition in the IF node and added a Code node, that emulates the first Jira node (I do not have Jira to test anything). Check the workflow.

That’s how I see it

I get the same results as you if I use a code node, but once the “check if ticket exists” node is set to active and routed like the way I show in my example, {{ $('Onboard/Offboard Switch1').item.json.fields['First Name']}} shows as invalid.

I swapped the “check if ticket exists” jira built in node to an HTTP request and the flow works fine with the last Jira node being able to pull {{ $('Onboard/Offboard Switch1').item.json.fields['First Name']}} (along with other fields). Maybe this is an issue when using two of the same nodes types?

One option is to use the Loop node. Like in the example

And the last option is to use the Code node to manually handle the items

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