Using Outputs from Other nodes in "Code"

Hey all,

I have a code node that should transform the input as shown in the first picture if i hard Code the Input that works withput a Problem.

However, using a variable ($input.item) as the Input results in a ERROR: Cannot read properties of undefined (reading ‘Test’) [line 4, for item 0].

What am i doing wrong?, if the Code just is

const inputJSON = $input.item;
return inputJSON;

i get the correct Input as Output as i would othwise hard code it in as seen in the first picture…

How do i corectly refer the Input ?

Hey @N0ah,
if your code is running in mode Run Once For Each Item the $input.item won’t be an array, it will be an object.

Can you try using const inputJSON = $input.item.json.Test?

2 Likes

Hey @marcus,
thanks for the quick answer, sadly that also doesnt do the job and returns a
“ERROR: Cannot read properties of undefined (reading ‘forEach’) [line 11, for item 0]
TypeError”

after consulting it again with a fresh mind and some trial and error we came to conclude that it works with Run Once for Each Item and:

const inputJSON = $input.item;

// Extract the 'Test' array from the input JSON
const testArray = inputJSON.json.Test;

Thanks a lot for the help !

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