How to access variable which is set in if and else

Describe the problem/error/question

I want to set a variable based on a if/else node. After that I want to use that variable in a message node, which has both the if and the else as input. I can’t reference the set node in the message node, since then the other case is not taken into account.

How can I use the variable no matter if it was set in the if or the else path? Thanks! (This is a overly simplified version of the actual workflow)

What is the error message (if any)?

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 1.82.1
  • Database (default: SQLite): SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: linux

You have two different types (numeric and string) and two different names (number and value) in your example workflow.

If you make both Set value and Set value1 set the same field name (e.g. commonValue), of the same type (e.g. string), then the HTTP Request node can generically reference the value from the previous node (whichever path was taken), using an expression like {{ $json.commonValue }}

If this answers your question, please mark this post as the Solution

Working Example

1 Like

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