IF/ELSE inside Expression

Is it possible to do an if/else inside of an Expression? I have an expression that currently references {{$node[“Webhook”].json[“body”][“attributes”][“ticket_id”]}}. The issue is that, as I’ve recently discovered, sometimes the data that comes in via the webhook uses ticket_id and sometimes it uses just id. So what I’d like to have happen is that if {{$node[“Webhook”].json[“body”][“attributes”][“ticket_id”]}} exists in the webhook data, it’s used, but if it does not exist it uses {{$node[“Webhook”].json[“body”][“attributes”][“id”]}} instead. In these situations where id is used instead of ticket_id, ticket_id is not there at all. Thank you.

You could use this expression:

{{  $node["Webhook"].json["body"]["attributes"].hasOwnProperty("ticket_id")
?  $node["Webhook"].json["body"]["attributes"]["ticket_id"]  :  $node["Webhook"].json["body"]["attributes"]["id"]  }}

This works, thanks Shrey, as always. FYI, some of your quotes are invalid so that would need to be cleaned up if anyone comes across this and it doesn’t work. Cheers!

1 Like

Thanks for letting me know that, Moez. Have now updated the quotes within the code.