Describe the issue/error/question
I’m having a relatively new problem to a workflow that has been running without a hitch for weeks now. What I’m doing is running a for…of loop inside the Function Node over the output of the Shopify Trigger Node, specifically the line_items key which is an array, and checking if the name of the product includes the word “Appointment” and if the product exists or is custom made.
One of 3 problems arises:
-
Iterates over the array but doesn’t find the word “Appointment” although it clearly being in the name of the product (I know it iterates because the product exists and the isCustomOrder flag that I default to true is then set to false) and therefore blasts through any IF Node checks I’ve put in place leading to an Error. This happens in the only in the Error Logs when coming from the Shopify Trigger.
-
It says that items[0].json.line_items is not iterable despite being an array, and working in the past. So far only seen on the Shopify Node.
-
It works…flawlessly. Which I kinda expect/hope for.
The line_items array output:
Is there a difference between the output of the Shopify Trigger Node and the Shopify Node? Running my own test with diff shows no difference between the Order Created Trigger and the Get Order Node but there may be some difference under the hood which I’ve encountered in the Read PDF Node output before.
Please share the workflow
Posting the reduced version for testing, whole thing is a bit too sensitive to be able to share.
Shopify Get Order into Function Node with for…of loop.
Having a dickens of a time trying to edit this code, ignore the last line, won’t post as code without it for some reason:
{
"nodes": [
{
"parameters": {},
"name": "Start",
"type": "n8n-nodes-base.start",
"typeVersion": 1,
"position": [
240,
300
]
},
{
"parameters": {
"functionCode": "items[0].json.isAppointment = false;\nitems[0].json.isCustomOrder = true;\n\nfor (item of items[0].json.line_items) {\n if (item.title.includes(\"Appointment\")) {\n items[0].json.isAppointment = true;\n }\n if (item.product_exists) {\n items[0].json.isCustomOrder = false;\n }\n}\n\nreturn items;"
},
"name": "Function1",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
660,
300
]
},
{
"parameters": {
"operation": "get",
"options": {}
},
"name": "Shopify",
"type": "n8n-nodes-base.shopify",
"typeVersion": 1,
"position": [
460,
300
]
}
],
"connections": {
"Start": {
"main": [
[
{
"node": "Shopify",
"type": "main",
"index": 0
}
]
]
},
"Shopify": {
"main": [
[
{
"node": "Function1",
"type": "main",
"index": 0
}
]
]
}
}
}
^Copy from here upwards
Stack Trace of the Function Node
TypeError: items[0].json.line_items is not iterable
at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Function:4:28
at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Function:14:2
at BaseHandler.apply (/usr/local/lib/node_modules/n8n/node_modules/vm2/lib/bridge.js:479:11)
at NodeVM.run (/usr/local/lib/node_modules/n8n/node_modules/vm2/lib/nodevm.js:425:23)
at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Function/Function.node.js:96:31)
at Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/src/Workflow.js:526:37)
at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/src/WorkflowExecute.js:451:62
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Information on your n8n setup
- n8n version: 0.171.0
- Database you’re using (default: SQLite): Default
- Running n8n with the execution process [own(default), main]: default Docker Server setup
- Running n8n via [Docker, npm, n8n.cloud, desktop app]: Docker