Get current iteration in code node

Hi,
I have a Gmail node which retrieves several mails. I have some other nodes and then a code node.
In this node, I want to get the current iteration of the Gmail node (if it’s the third mail, I want this mail infos).
In my code node, I have this:

const body = $('Gmail').all()[0].json.snippet;

But, that returns me the first mail of the list, not the current one… (and this is normal due to the [0]).

So my question is how to get the key of the actual mail in the loop ?

Here is a piece of my workflow for comprehension:

Thanks !

Hi @CodeRider883, it looks like your code node is configured to run for all items at once. So there is no current item.

A very simple way to assign an index value to your items would be to add a Set node after your Gmail node, then add a new field with an expression such as {{ $itemIndex }}:

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