Run down a tree for each item and collect results

Describe the issue/error/question

Hi! I want to iterate over all items where each item has to go through some conditions and yields a result using the “Set” node at the end of each row. When all items were then want to collect the results using the collect commands node where I have all outputs of all 4 set nodes and combine them into a single array. But I cannot access the results of the set nodes because the workflow says that I have to execute them. How can I solve this?

Please share the workflow

Share the output returned by the last node

None

Information on your n8n setup

  • n8n version: 0.220.0
  • Database you’re using (default: SQLite): SQLite
  • Running n8n with the execution process [own(default), main]: main
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: Docker

Hi @markusstephanides, welcome to the community!

This won’t work unfortunately as your Collect commands node has no relation to the Set nodes it references.

Perhaps you can rewrite your workflow in a way that the Set nodes connect to your Extract Comments and Collect commands nodes (if these depend on your Set nodes)? Something like this:

Combining them into a single array is a whole different beast. You can in theory use the Merge node for this, but it will trigger all incoming branches to run even if they shouldn’t:

This will change in the future, but for now it’s important to keep in mind.

Hi!

I was using the merge node before but as you said, it triggered all nodes before it and with that HTTP Requests even though it shouldn’t.

Would it help to replace some of the logic with code nodes?

Yes, you could consider using a Code node, I’ve shared one possible approach over here: [Merge node] merging multiple outputs - #4 by MutedJam

It might be easier/more readable for you to do something like this though:

  1. Move the tree logic into a sub-workflow
  2. Split your workflow in batches of 1 and run the sub-workflow for a single item at a time
  3. Create a single list from all batch items again afterwards (check Addition assignment (+=) operator with the Set node in n8n - #5 by BramKn for options)

So essentially one “parent” flow like this:

And one sub-workflow like so:

Hope this helps :slight_smile:

1 Like

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