Cannot read properties of undefined (reading '0')

Describe the problem/error/question

Hello!
I have a main workflow which uses 2 workflows, one workflow update a google sheets and the other one Notion, the data is updated with a Shopify Trigger.
However on of them are getting the error described at the subject.
I reported another case previously here.
I made the adjustments suggested but now I am experience the same error.
Which is intriguing, is I have no problems with Google Sheets (first workflow), the problem is the second one (Notion).

the error is reported in this line:
Payment_Method: inputData.payment_gateway_names? ‘’ : inputData.payment_gateway_names[0],

Which I understand I am doing here is validate the field payment_gateway_names is not “UNDEFINED”. But look like it doesn’t work.

I shared the execution error message.

In the flow I shared I changed the code to:
Payment_Method: (inputData.payment_gateway_names?.length || 0)===0? ‘’ : inputData.payment_gateway_names[0],
I hope this new validation works.

I really don’t understand why n8n found the field as “UNDEFINED” since the value exists and is correct.
This is the current data fetched from Shopify:
“payment_gateway_names”: [
“paypal”
],

What is the error message (if any)?

Cannot read properties of undefined (reading ‘0’) [line 136, for item 0]

Please share your workflow

https://drive.google.com/drive/folders/1UNrNslzEOsvHeDxosvqjmgTb4jrc37Ve?usp=sharing

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

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

@ingeniux , the 2nd sub-workflow will use the data returned by the 1st sub-workflow, not the Shopify data.

  • What does 1st sub-workflow return? Does it has the the values you are trying to access in the 2nd sub-workflow?
  • Do you intent to use 2nd sub-workflow after the 1st sub-workflow completed (meaning the 2nd sub-workflow has to use data returned by the 1st sub-workflow)?

Perhaps you meant to use the below workflow instead?

hello @ihortom
I want to use the data fetched from Shopify for both sub-workflows.
The sub-workflows will process the same data only to different database.
So in this case, I think your approach is correct.
I will change the main workflow as you suggested, I hope solve the issues.

Thanks for your feedback.

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