Expression for Router
I have a Router snap which evaluates whether an ID exists for records returned in a Salesforce Read Snap. Some of these have an ID, others do not.
Right now in the Router snap I have an expression for those that does, '$Id != null, but I can’t work out what the negative should be since both the Id:XX key, value pair does not exist.
Here are the example JSON messages:
ID Exists:
{
"Id": "0013H00000H1FZiXXN",
"original": {
"FirstName": "X",
"LastName": "X",
"Account": {
"attributes": {
"type": "Account",
"url": "/services/"
},
"Name": "X"
},
"Id": null,
"input1_FirstName": null,
"input1_LastName": null,
"input1_Account": null
}
},
ID does not Exist:
{
"original": {
"FirstName": "X",
"LastName": "X",
"Account": {
"attributes": {
"type": "Account",
"url": "/services/"
},
"Name": "X"
},
"Id": null,
"input1_FirstName": null,
"input1_LastName": null,
"input1_Account": null
}
},
Hi @NAl,
You can do this with the .get() method. The first parameter you pass to this method is the field you are looking for, and the secondary parameter is optional - you pass the value you want to be returned if the field you are looking for it’s not found, just like in your case.
So instead of checking with
$Id != null
, what you can do is$.get("Id", null) != null
. In this case, even if the “Id” is not present in the input document the expression will evaluate to false.