Describe the problem/error/question
I’m working on a workflow where I need to accumulate results from each loop iteration and pass them to the next iteration. Each iteration needs to know what was done in previous iterations to avoid duplicating the repetition in the generated content. I’m generating content paragraph by paragraph. N8N sends data via http request to the workflow in dify.
What I’m trying to achieve:
I have a loop that processes items and generates content. Each iteration must:
- Know what content was already generated in previous iterations
- Generate new content based on new data and what’s already done
- Add its result to the accumulated output
Example flow:
- Iteration 1:
done = ""
(empty) → generates “Result A” →done = "Result A"
- Iteration 2:
done = "Result A"
→ generates “Result B” →done = "Result A\nResult B"
- Iteration 3:
done = "Result A\nResult B"
→ generates “Result C” →done = "Result A\nResult B\nResult C"
The challenge: I need to pass the accumulated “done” variable from one loop iteration to the next within the same loop execution. The number of iterations varies based on input data size (number of headings in the brief).
What I’ve tried:
- Using
$workflow.staticData
- getting “Cannot set properties of undefined” errors - Trying to reference previous iteration results - not sure how to access them properly
- Accumulating “done” in google docs, but it doesn’t seem like the the best possible solution.
Question: What’s the best practice in n8n for maintaining and updating state across loop iterations? Is there a pattern for accumulating results where each iteration builds upon the previous ones? For example, in make.com for the same task I used “set variable” and “get variable” nodes. With that I was able to pass data from the finished iteration to the next iteration.
Any examples or guidance would be greatly appreciated!
Please share your workflow
This is a simplified version of the workflow.
Information on your n8n setup
- n8n version:: 1.97.1
- **Running n8n via Docker