Describe the problem/error/question
Hi everyone,
I had opened an topic in this forum about how to make a counter inside of n8n. Now, I wanted to improve and make it more dynamic pipeline. So here is the question: I have a workflow where I process multiple links using a Loop Over Items node. Inside this loop, there is a sub-loop (polling an API) that uses an If Node to limit the number of attempts.
The Problem: I wanted to use {{ $runIndex }} or {{ $input.all().length }} as a counter to stop the polling after 10 attempts. However, these values are cumulative across the entire execution.
When the main loop moves to the second link, $runIndex doesn’t reset to zero. It starts from where it left off (e.g., 11, 12, 13…), which immediately triggers the “Limit reached” condition in my If Node, causing the second item to fail instantly.
My Questions:
-
Is there any way to reset the
$runIndexfor a specific node when moving to the next item in a parent loop? -
If not, what is the best practice to implement a “per-item” counter that resets every time a new item enters the sub-loop without making the workflow too messy?
I tried using a Code Node to increment a counter variable, but I’m struggling with data persistence between the iterations of the polling loop.
Any advice would be great!
What is the error message (if any)?
N/A
Please share your workflow
Share the output returned by the last node
Information on your n8n setup
- n8n version: v2.13.4
- Database (default: SQLite): default
- n8n EXECUTIONS_PROCESS setting (default: own, main): main
- Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
- Operating system: Ubuntu 24.04

