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 }}