Editing a "variable" within a loop

I have a text with some placeholders. Safed in a Set-Node (I need variables!). Now I want to replace each placeholder with a different value. I configured a loop an it works for each single replacement.

BUT I get e.g. 3 outputs. Each with one replaced placeholder. I want to have the complete text with all placeholders replaced.

So I need to access the initial Set-Node from within the Loop and edit the Set-Node and then use the newly altered Set-Node. Unfortunately, I always get the initial value of the set node.

How can I realize this use case?

Share the output returned by the last node

Information on your n8n setup

  • **n8n version: 1.9.1
  • **Database (default: SQLite):MySQLlite
  • **n8n EXECUTIONS_PROCESS setting (default: own, main):default
  • **Running n8n via: Docker
  • **Operating system:I don’t know

Welcome to the community!

I think i know what you’re saying, but it’s really hard to imagine and suggest fixes without seeing your workflow.

please embed your workflow like this and we can help you a bit better

Thanks, @liam

Here is the flow:

At the end of the Loop1 I do need only one text with all replaced items. Hopefully that helps.

I can not find a way to do it without code node.

So here is my solution

This is your expected result right?

3 Likes

@darrell_tw, thank you very much! I already doubted that the code node is necessary.

Thanks for your help and pointing me in the right direction!

I also always use the code block, but you can do it with a set node like this.

The key things to keep in mind is to reference the field using dot notation object.message so it matches the position of the original object and then enable the "Include Other Input Fields option

It might work in my simple example, BUT in more complex workflows the code block should be used to easily reference previous nodes by name like in @darrell_tw solution

2 Likes

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