Pair data ('list id' and 'task') from different nodes


I’m creating a workflow for deleting Microsoft To Do’s if they are completed, for all Lists I have.
I don’t want to add a node for each list, so i’m trying to do it all in n8n.

For deleting a Task, I need the List ID.

I tried to add a field list_id with the Set node, and using the parameter List ID from the node getting all tasks. But I’m getting each list id only once, on the first 8 (number of lists) items. The other items have a empty ‘list_id’
I think n8n iterates per dataset/node…?

So, how to pair the Task item with its Lists ID?

Schermafbeelding 2021-11-25 om 21.52.29

Welcome to the community @yoaz

You are right. It does. I think the issue happens because the parameter you are referencing in the set node it’s referencing an expression in the first node. Never seems this scenario before.

I will sync with my coworker about this and come back to you. In the meantime, you can use the workflow below to achieve that.

1 Like

Thanks! That is some advanced stuff, trying to understand that workflow.

It didn’t give the result I need. So I was tweaking it with trial & error (learning how n8n operates and can do) and I have made it work.
I want to share my work:

The use of the split in batches node was clever. Thanks @RicardoE105.

The node which gets all tasks per list was still using the expression from the first node, not the SplitInBachtes node, so i corrected it.
That was workig (the right data was paired). But when a list is empty, the run stopped. So I set ‘Always Output Data’ option on.

The function node for. merging all run on the set node was executed on the first run. So the merge node in wait mode was not waiting for all runs to finish.
I now use an If node to check for the SplitInBatches context. ‘noItemsLeft’.

I added a function node for filtering out those items from empty lists (which don’t have a task_id field).

Finishing off with an if node for checking if task is completed and an node for deleting those task, and it’s all working now!

Here the workflow code, for those who want to use it also (since Microsoft To Do’s doesn’t have a function for deleting completed tasks…)

1 Like

Great that you figured it out.

This use case is infrequent. First time I’ve seen it in two years. Usually, the API would have returned the list id, meaning you would not have needed to reference the parameter in the second node, which is referencing an expression in the first node. I would speculate that in 98% of cases, you do not need these many nodes for such a simple workflow. I spoke with Jan about it, and this is how it was initially designed, and at some point, we will improve to cover cases such as this one.

1 Like

Thanks for the reply and your explanation. I understand it is an infrequent use case. To bad this API does not follow that principle.
Luckily n8n provides enough tools to accomplish it. Thanks for the work you all are putting in.