Switching between variables depending on which path was executed

I have a workflow that looks like this:

As you can see, there are two potential triggers for it. In the HTTP request node, I need to change a parameter based on data from either the webhook or the date & time node.

My current solution that works is using an inline if/then statement to return nothing if the variable doesn’t exist like so:

{{ data ? data : “” }}

But what I really wanted to do is:

{{ data_source_1 ? data_source_1 : data_source_2 }}

This is a more elegant solution, but I found that it didn’t work. The path that wasn’t executed was not treated as a false boolean, it just returned “not found”.

Here’s the relevant part of the workflow:

Hi @Giovanni_Segar, you should be able to use the ternary operator if you want, check out this example:

The problem with your workflow will most likely be expressions such as $json["body"]["date_to"] assuming your top branch doesn’t provide a body object. You might want to consider optional chaining for such cases, check this example:

That’s what it was. I assumed it’d give me “false” or undefined for a missing object. Doing $json.body?.date_to worked.

1 Like