error while executing a function n8n

Good afternoon, I ask for your help while executing the simple function
"item.myVariable = $ node [" Telegram Trigger "]. Json [" message "] [" text "]. Substr (15); return item; "

I get an error

ReferenceError: item is not defined
    at / usr / local / lib / node_modules / n8n / node_modules / n8n-nodes-base / dist / nodes: 1: 98
    at Object. <anonymous> (/ usr / local / lib / node_modules / n8n / node_modules / n8n-nodes-base / dist / nodes: 3: 2)
    at NodeVM.run (/usr/local/lib/node_modules/n8n/node_modules/vm2/lib/main.js:1167:29)
    at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Function.node.js:81:31)
    at Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/src/Workflow.js:517:37)
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/src/WorkflowExecute.js:447:62
    at processTicksAndRejections (internal / process / task_queues.js: 95: 5)

Hi @This_is_real_life, welcome to the community! I hope you’re having a good Friday?

Is this a snippet of code you are using in a Function node? This node would not execute for each individual item through the item variable but rather runs for all items using the items array.

So depending on what you are trying to achieve, you might need to loop through the items yourself or specify the item you want to access. The documentation above includes some well documented examples to help you get started.

If you’re still running into trouble after going through these, could you share your workflow (removing all confidential data, of course)?

Yes I am using Function node. n8n was purchased on a test machine, without using docer, I work via WEB, there are no such problems on another test machine.

@This_is_real_life Can you share your function code like @MutedJam mentioned? Looking at the error it would suggest that the incoming items variable has not been looped like the example shows and that is causing your error.

item is only available in the “Function Item”-Node not in the “Function”-Node.

You can find the documentation here:

3 Likes

Thank you very much, from the bottom of my heart, as they say in our homeland “I would be a girl 100% would give myself”