Output if exists

Hello guys.
I am going to make a text with some input fields.
inputs : url01 - url02 - url03
my text file will be : your first url is {{url01}} and second is {{url02}} and third is {{url03}}.
if all inputs are available the out put is ok, but if second and third are not available the out put shows like this :
your first url is {{url01}} and second is [undefined] and third is [undefined].

how to set it to write the output length based on the input ?
if we have url01 : your first url is {{url01}}.
if we have url01 and url02 : your first url is {{url01}} and second is {{url02}}.
if we have all of them : your first url is {{url01}} and second is {{url02}} and third is {{url03}}.

i know i can use switch node, but my outputs are more than 4.

thank you.

Hey @rhodesgod,

The quickest approach would be to use a code node to build out your message based on the inputs but you could also do something with a ternary operator in an expression if you wanted to. It may be a bit different if url03 is set and url02 isn’t so I would probably look at using the code node instead so you can count the urls and work out how many to display it will also allow you to scale a lot easier as well.

1 Like

i should search for ternary operator ?

if url03 is available url02 is there too.no exception.

Here is a quick example using a ternary operator in an expression, If you run the workflow you can change between the 2 different results on Set1 by changing the run on the output view.

1 Like

this works perfect. the only problem is syntax.

i want to put url between " url " , but it shows only the code, not the value.

{{ $json.url01 ? ’ your first url is “$json[“url01”]”’ : ‘’ }}

the output is : your first url is “$json[“url01”]” but it want to be like this : your first url is “www.google.com

thanks.

Hey @rhodesgod,

It should just be a case of adding the " in the string and adding a + '"' at the end of each true condition like this…

1 Like

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