cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Expression for Router

NAl
Contributor

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
    }
  },
1 ACCEPTED SOLUTION

j_angelevski
Contributor III

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.

View solution in original post

3 REPLIES 3

j_angelevski
Contributor III

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.

NAl
Contributor

Thank you, thatโ€™s done the trick

Kanika
New Contributor

Hi,

Another way of doing this, 'Id' in $ && $Id != null where the first condition checks if Id is present in the input payload and second one checks that its not null.