Function Node: Access all items from previous node output

I have a Workflow that goes something like this:

  1. Run
  2. Get Tasks: HTTP Request
  3. Filter Tasks: Function
  4. Get Folders: HTTP Request
  5. Filter Folders: Function
  6. Combine Tasks and Folders: Function

In step 6, I need to use the output from both 5 and 3. 5 is just items, so that’s fine. But, I’m having trouble getting all of the output from 3.

I’ve tried $node["Filter Tasks"].json which only gives me the first item. I’ve also tried $item(0).$node["Filter Tasks"].json, which gives me the same thing. $item(1).$node["Filter Tasks"].json gives me the second item. But, since I don’t know how many items are returned in that node, I can’t just get $item(0), $item(1), etc.

I can’t figure out how I just get all of the items from the “Filter Tasks” node, and I don’t see anything in Function | Docs or JavaScript Code Snippets | Docs that tells me.

You can use $items(). So in your case that would be:

const allItems = $items("Filter Tasks");

You can find the documentation here:
https://docs.n8n.io/nodes/expressions.html#method-items-nodename-string-outputindex-number-runindex-number

3 Likes

Thank you so much! That link is very helpful.

Great to hear! Have fun!

Hi @jan, I am jumping on the topic:
I’ve tried this solution and it’s working, but there is a way to do it without connect the node between them?
Cause, like this I have to connect my node with the data to the code node
For example:

Sorry, I am not sure I understand. Some kind of indirect connection is required (so multiple nodes can be inbetween). But no direct connection is required.

Sorry for bad explanation.
So basically, I need to take the output of get list2 and use in code2, but this system works only if I connect the 2 nodes together (like screenshot).

What happens if you do not connect them and how does your code look like? Because it should work.