No fields - item(s) exist, but they're empty error

Describe the problem/error/question

This is my first post here. Im just starting with n8n.
I have an issue in code node.
The input pane on the left show me
“No fields - item(s) exist, but they’re empty” after I test the code node,
However prior testing when I just double click on the node the value is visible.
Is the node not executed because not connected wiith the triger? Well even if I connect it, it does not work.
Here is the code in the code node:

import json
a = json.loads(_input.all()[1]["json"]["param"])
raw_data = json.loads(_input.all()[0]["json"]["redditdata"])
author = "LilFingaz"  # na stałe

comments = raw_data[1]["data"]["children"]
comment = next((c for c in comments if c["data"]["author"] == author), None)

if not comment:
    return {"json": {"error": f"Comment by author {author} not found"}}

item = {
    "author": comment["data"]["author"],
    "body": comment["data"]["body"],
    "id": comment["data"]["id"],
    "upvotes": comment["data"]["ups"]
}
return {"json": item}

i think its something simplei have not understood yet. thank you

What is the error message (if any)?

Please share your workflow

Sorry it is my first post. When I paste my workflow i get error posting, it says body is to long. Please guide eme.

(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:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Can you copy only the nodes related to the case (Code node, then node before it and the node after it)?

You can copy it with ctrl+c. Then past the content here after pressing button </> with ctrl+v.

No, even only 3 nodes is to much. It is because i have big json object in jsonData node.
thank you

This approach doesn’t work as expected. The Node param is never executed, and it doesn’t pass the parameters to the Code Node. n8n processes the workflow step by step, moving from the start to the end. If additional parameters are required, a Node needs to be added in between the other Nodes.

Thank you.
How can i load data from fields in both nodes (jsonData and param) to separate variables in python?

The easiest way is to enable the Include Other Input Fields option on the param node. This will add the new variables to the item.

i was actually asking for the python syntax to input into code node

This is only possible when the param node is connected as shown by Franz. If you connect it like in your screenshot, it never gets executed and you cannot reference the output data in your code node.

Use the “Include Other Input Fields” and access the data from previous node like you already did in your code example.

When Include Other Input Fields is enabled, then data from the node before is passed and can simply be used in the code node.

When iterating over items, parameter can be accessed as item.json.parameterName.

e.g.

for item in _input.all():
  item.json.param3 = item.json.param1 + item.json.param2
return _input.all()
1 Like

Yes, I understand. I did connect it as he sugested but still no luck/understanding how does python syntax has to look inside the code node.
perhaps i got myself confused with to complex start. I should first understand how to assign variables in python from fields in set nodes.

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