Code node failing to take inputs from multiple previous nodes

when I try to take input values from multiple nodes into a code node, the values are not successfully referenced, in the code node, I want help to fix this issue, as I am stuck in this node without getting a way to get the input into this code node.

Example code below:

Safely extract the user’s selected number (e.g. from chat/text)

selected_text = {{ $node[‘Edit Fields1’].all()[0].json.SelectedNumber }}

Convert to integer

try:
selected_number = int(selected_text)
except:
return {“message”: “Invalid input. Please reply with a number.”}

Convert user number (1-based) to 0-based index

index = selected_number - 1

Get categories from the current item

categories = _item[“json”][“categories”]

Validate index range

if 0 <= index < len(categories):
selected = categories[index]
category_name = selected[“category”]
count = selected[“count”]

# Generate category slug (replace spaces and special chars)
slug = category_name.lower().strip().replace(" ", "-")
link = f"https://soundaryasarees.com/product-category/{slug}/"

# Create formatted HTML-like message
message = f'<li class="cat-item"><a href="{link}">{category_name}</a> <span class="count">({count})</span></li>'

return {"message": message}

else:
return {“message”: “Invalid selection. Please enter a valid number from the list.”}

In this code I am expecting the value for : selected_text = {{ $node[‘Edit Fields1’].all()[0].json.SelectedNumber }}

but the value is not passed from previous nodes, and it causes errors when I try to execute. if some one has any solution, please help?

To reference inputs from multiple nodes in a Code node, use the `$(“node-name”).all()` method to access data from each node separately. For example, to get data from “Edit Fields1” and another node, you can do:

```python

selected_text = $(“Edit Fields1”).all()[0].json.SelectedNumber

other_data = $(“AnotherNode”).all()[0].json.SomeField

```

Ensure that the data structure returned matches what you expect. For more details, refer to the [docs.n8n.io]( Output of other nodes | n8n Docs ). If you still face issues, check if the nodes are correctly connected and the data is being passed properly.