Variable used in future nodes based on variable in current node

No errors, just me having a brainm fart

I need a node that tells my workflow this:
if INBOUND is in the “direction” field, use the from phone number
if OUTBOUND is in the "direction field, use the to phone number

I don’t want seperate branches in the outcome, so I can’t use switch
the fields are already set, I just need something that changes one of the two phone numbers coming in to be THE phone number it uses from then on out in the workflow

what’s the best option for this?

It looks like your topic is missing some important information. Could you provide the following if applicable.

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

@djjace , use an expression, something like this

phone_number = {{ $json.direction == 'INBOUND' ? $json.from : $json.to }}

It’s called a ternary operator.

4 Likes

That’s elegant and compact! :ok_hand:

1 Like

To add to this. n8n also provides some functions to help Convenience methods | n8n Docs
The $if() does basically what the ternary operator does.
for example
{{ $if($json.direction == 'INBOUND',$json.from,$json.to) }}

1 Like

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