Not able to fetch a previous node data if a node fails

I have a postgresql query node after which if query fails to return data, data from a earlier node is not accesible in the “code” node.

let inputData = {}
console.log(“Data”,JSON.stringify(inputData))
console.log("Type : ",typeof($input.item.json.awb))
console.log("Values : ",$(‘Validator’).item.json.barcodes[0])
if(typeof($input.item.json.awb)!==“undefined”){ inputData = $input.item.json
}
else{
inputData.awb =$(‘Validator’).item.json.barcodes[0]
inputData.sortId = “null”
}
console.log(“Data2”,JSON.stringify(inputData))
$input[“item”] = inputData
return $input.item;

Code fails at the bold line with error as below

Item Index: 0

Stack

ExpressionError: Can’t get data
    at createExpressionError (/usr/local/lib/node_modules/n8n/packages/workflow/dist/WorkflowDataProxy.js:422:20)
    at getPairedItem (/usr/local/lib/node_modules/n8n/packages/workflow/dist/WorkflowDataProxy.js:478:27)
    at pairedItemMethod (/usr/local/lib/node_modules/n8n/packages/workflow/dist/WorkflowDataProxy.js:672:40)
    at Object.get (/usr/local/lib/node_modules/n8n/packages/workflow/dist/WorkflowDataProxy.js:675:40)
    at get (<anonymous>)
    at VM2 Wrapper.get (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/[email protected]/node_modules/vm2/lib/bridge.js:447:11)
    at /usr/local/lib/node_modules/n8n/packages/nodes-base/dist/nodes/Code:4:39
    at /usr/local/lib/node_modules/n8n/packages/nodes-base/dist/nodes/Code:15:2
    at VM2 Wrapper.apply (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/[email protected]/node_modules/vm2/lib/bridge.js:485:11)
    at Sandbox.run (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/[email protected]/node_modules/vm2/lib/nodevm.js:426:23)
    at Sandbox.runCodeEachItem (/usr/local/lib/node_modules/n8n/packages/nodes-base/dist/nodes/Code/Sandbox.js:140:42)
    at Sandbox.runCode (/usr/local/lib/node_modules/n8n/packages/nodes-base/dist/nodes/Code/Sandbox.js:30:87)
    at Object.execute (/usr/local/lib/node_modules/n8n/packages/nodes-base/dist/nodes/Code/Code.node.js:98:38)
    at Workflow.runNode (/usr/local/lib/node_modules/n8n/packages/workflow/dist/Workflow.js:659:51)
    at /usr/local/lib/node_modules/n8n/packages/core/dist/WorkflowExecute.js:585:68
    at processTicksAndRejections (n

Hi @Navaneeth_P_K, welcome to the community :tada:

I am sorry to hear you’re having trouble. The .item property you are using is not fully supported in the Code node I am afraid. You might want to check this docs page for a full list of methods and variables.

Seeing your Validator node only returns a single item, perhaps you can use .first() instead?

Thank you, it was very helpful.

1 Like

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