Question about Looping


I’m trying to create a workflow that contains loops. I want to get the correct item from a previous node (Get Task Details) in a Function node (Get Key Mapping).

I tried to use function methods to retrieve item but it needs index of item and I don’t know how to configure and put the index in here.

How do you handle these types of workflows?


Hey @samaritan, I assume you are using $items() in your Function code?

Indices are 0-based, so the index of your first item would be 0, the index of the second item would be 1 and so on. This does not change by the loop (the loop would only increase the run index of the nodes inside the loop).

Here’s a simplified example of a workflow first looping a bit and then running a Function node retrieving data from before the loop:

The code used here is fairly simple:

// Fetch Items from the first run of another node
initialData = $items('Initial Data', 0, 0);

// Now return the first (and only) item of our 'Initial Data' node
return [

Edit: The return statement above is functionally identical to return initialData (which would return all items). I’ve used return [initialData[0]] instead to show how to return an item at a specific index (0 in this case) based on your question.

Hope this helps! Let me know if you have any questions on this.

Hi @MutedJam, thank you for your help. The expression is helpful but I want to get current item of loop. I think like there are nested loops and I want to get the current item from “Get Task Details”. Even if I get the whole data, I can’t know which item is the current one. There are 2 items that passed from if statements and I have to know which item belongs to an item from main loop (Get Task Details).

What is your comments?

Thanks for your help.