Possible to reset the $runIndex of a node?

Describe the issue/error/question

Possible to reset the $runIndex of a HTTP Request node programmatically ?

I am running a HTTP Request node in a nested loop (batch inside batch), and using $runIndex as my “page number”.
Problem is - it is just continuing to increment even when the outer loop has incremented, whereas I need to be able reset $runIndex programmatically, as I need to reset to page “0” for the next loop of the outer batch.

Are there better ways of dealing with this “page number” tracking with the ability to programmatically reset it ?

Can you share a sample workflow JSON?

Otherwise I’d try using the $position variable that will get reset after SplitInBatches, or maybe using $runIndex modulo the batch size? E.g. {{ $runIndex % 10 }}

Hey @atomtr,

What about using a set node at the start to set page to 0 then in your look you can use a set node node again to set the page value to either +1 or 0 depending on where it is.

Thank you for your replies @pemontto and @jon !

@pemontto - I cannot use modulo because its technically not a fixed batch size, instead its “pages” which changes from item to item.

@jon - sorry, I don’t yet get what you mean (new to n8n, and hoping to get the hang of it soon :slight_smile: ). Would you be able to help with a example with this workflow please ?
I tried another example with a set, but couldn’t figure out how to update/change the value of page in Set.

Here is a workflow that you should be able to run and see what I am trying to do.

Upon running it - you will notice in the http request params that for item 2 and 3, the page doesn’t start from 0, which is what I am looking for.

http request params as the workflow progresses -
{ itemId: 1, page: 1 }
{ itemId: 1, page: 2 }
{ itemId: 1, page: 3 }
{ itemId: 1, page: 4 }
{ itemId: 1, page: 5 }
{ itemId: 2, page: 6 }
{ itemId: 3, page: 7 }

Hey @atomtr,

So I was thinking something like this, It may need some tweaking but should help.