Reference to previous node item.json['abc'] not working

Describe the problem/error/question

Hi folks,

I’m very new to n8n and this maybe a newbie on training wheels problem. If so, please excuse my ignorance and kindly point me in the right direction.

What I’m trying to do is to create a workflow that retrieves a list of rss feeds from a google sheet, runs a workflow to fetch the items from the feed and then publish it on to MQTT via an expression template.

Trouble is that it is not succeeding in retrieving a reference to an item.json from a previous node.

{
     "title": "{{ $json.title }}",
     "content": "{{ $json.contentSnippet }}",
     "link": "{{  $json.link }}",
     "source": "{{ $('Google Sheets').params["documentId"]["value"] }}"

}

What is the error message (if any)?

The error message displayed is,

ERROR: Can’t get data for expression under ‘Message’ field

To fetch the data from other nodes that this expression needs, more information is needed from the node
Execute Workflow

Stack trace reads,

ExpressionError: Can’t get data for expression
    at createExpressionError (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/WorkflowDataProxy.js:453:20)
    at getPairedItem (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/WorkflowDataProxy.js:506:27)
    at pairedItemMethod (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/WorkflowDataProxy.js:714:40)
    at Object.get (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/WorkflowDataProxy.js:717:40)
    at Proxy.eval (eval at _create (/usr/local/lib/node_modules/n8n/node_modules/@n8n_io/riot-tmpl/dist/tmpl.js:388:14), <anonymous>:3:568)
    at Proxy.eval (eval at _create (/usr/local/lib/node_modules/n8n/node_modules/@n8n_io/riot-tmpl/dist/tmpl.js:388:14), <anonymous>:3:647)
    at Object._tmpl (/usr/local/lib/node_modules/n8n/node_modules/@n8n_io/riot-tmpl/dist/tmpl.js:335:60)
    at Expression.renderExpression (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/Expression.js:205:25)
    at Expression.resolveSimpleParameterValue (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/Expression.js:184:34)
    at Expression.getParameterValue (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/Expression.js:273:25)
    at getNodeParameter (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/NodeExecuteFunctions.js:1286:42)
    at Object.getNodeParameter (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/NodeExecuteFunctions.js:1508:24)
    at MqttClient.<anonymous> (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/MQTT/Mqtt.node.js:223:44)
    at MqttClient.emit (node:events:525:35)
    at MqttClient.emit (node:domain:489:12)
    at Readable.<anonymous> (/usr/local/lib/node_modules/n8n/node_modules/mqtt/lib/client.js:1570:14)
    at Readable.emit (node:events:513:28)
    at Readable.emit (node:domain:489:12)
    at endReadableNT (/usr/local/lib/node_modules/n8n/node_modules/mqtt/node_modules/readable-stream/lib/_stream_readable.js:1003:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • **n8n version:0.231.3
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • **Running n8n via (Docker, npm, n8n cloud, desktop app):Docker on a QNAP
  • Operating system:

Thank you in advance.

Kind regards
Kheeran

Hi @kheerand, I am sorry you are having trouble. I gave this a go on my side but didn’t run into any problem here when running your workflow on [email protected]:

This is of course with my own sheet and sub-workflow which would be different from yours.

In general, an error message such as “To fetch the data from other nodes that this expression needs, more information is needed from the node ‘Execute Workflow’” would be shown when using an expression relying on linked items, but your example expression does not seem to do this.

Are you also running into this problem when removing the "{{ $('Google Sheets').params["documentId"]["value"] }} part of your expression temporarily (so only use the simple $json... expressions instead?

Tanks for the help. Yeah, it works fine when substituting "{{ $('Google Sheets').params["documentId"]["value"] }}" to the workflow.

The Google sheet is fairly simple and is read without a problem.

image

Still baffled…

Kheeran

Thanks for confirming @kheerand! Seeing this expression is causing the problem for you, perhaps you want to use a Set node immediately after the Google Sheets node (and thus before the Execute Workflow node) that adds a new field with your sheet ID?

Like so:

Assuming none of the nodes in your workflow overwrite or remove this field you could then simply reference it using an expression like {{ $json.sheet_id }} which hopefully won’t cause any trouble:

Tom,

Tried that but no luck. However, it seems that the issue is related to Execute Workflow node. I rewired the MQTT node directly out of the Switch node, and it works fine. Is it that Execute Workflow node doesn’t pass through the details of the previous nodes, or looses it somehow when executing the other workflow?

Hi @kheerand, there is indeed a good chance the Execute Workflow node doesn’t fully support paired/linked items due to its nature of essentially wrapping an unknown other workflow.

However from looking at your workflow it seems you are still using an expression other than $json in your MQTT node. What happens if you use the the workflow I’ve suggested, replacing

{ 
    "title": "{{ $json.title }}",
    "content": "{{ $json.contentSnippet }}",
    "link": "{{ $json.link }}",
    "source": "{{ $('Google Sheets').item.json.Source_name }}"
}

with

{
     "title": "{{ $json.title }}",
     "content": "{{ $json.contentSnippet }}",
     "link": "{{  $json.link }}",
     "source": "{{ $json.sheet_id }}"
}

on your MQTT node, and instead use your {{ $('Google Sheets').params["documentId"]["value"] }} expression on the Set node before the Execute Workflow node?

This way, n8n would only read data coming directly from the Execute Workflow node, and nothing from before this node. Are you still seeing the same problem?

Hi Tom,

I tried the code you suggested, but the $json object didn’t have the sheet_id when it got to the MQTT node. This was of course handled more gracefully and instead of failing, simply passed on a empty value.

I’ve worked around this by wiring a merge node from Google sheet node, Execute workflow node and then passing it on to the MQTT node.

I’ve got a workaround now, so its good, but it does feel quite inelegant.

Cheers
Kheeran

1 Like

Hi @kheerand, the Merge node would have been the second approach. I know it’s not particularly elegant but it’s quite common (I actually suggested it just last week in a different context). So personally I am still rooting for a “Also keep incoming data” option on our nodes.

Either way, I am glad to hear you found a working approach now :slight_smile:

Yeah, nothing wrong with using the merge node, that’s what would have to happen behind the scene anyway to ‘also keep incoming data’, but yeah, looks inelegent.

Cheers
Kheeran

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