Advanced IF in Expression

Well, advanced to me. :slight_smile: I’m looking to clean up some of the alerts that we pass through n8n to Matrix. In the case of our website monitoring platform, some of the fields it sends via webhook are empty unless the issue is resolved. So, as a basic example, we have something like this in our notifications:

resolved at {{$node["Webhook"].json["body"]["data"]["attributes"]["resolved_at"]}}

If the issue is new, “resolved_at” will have a value of null, whereas if it’s resolved, the value will be something like “2021-10-13T17:10:52.778Z”. What I’d like to be able to do is have the entire line starting at “resolved at” through to the end of the variable only display if “resolved_at” is not null. And I’d like to do it without a separate IF node, ideally. I’ve seen other posts in here about doing something similar around replacing the variable with another variable (thanks again for that @shrey-42) or replacing the variable with arbitrary text if it’s missing, but not exactly this. Thanks in advance!

Hey @cleveradmin,

Are you after the ternary operator?

Kind of. I think a variation on that might work. The difference is that instead of just the variable, I’d want to prepend it with the text “resolved at” and if the variable is empty, show nothing. I’m not sure how to go about that.

It would be the same thing, using the same example from the snippets page the below should work.

{{$json["variable_name"]? "Resolved at " + $json["variable_name"] :""}}

Thanks @jon, this appears to do what I need. Just waiting for an outage to know for sure. Cheers!