Router Snap Expression for checking Value

We have a Router Snap that evaluates a string and checks whether it matches one of a set of predefined values. I can’t seem to get the expressions right and think a short circuit evaluation is at play here?

The logic is as follows

  1. If Status CONTAINS either X, Y or Z then send to Output A
  2. If Status DOES NOT CONTAIN either X, Y or Z then send to Output B

The logic I started with before looking at the contains and includes functions

  1. $Status == (‘X’ || ‘Y’ || ‘Z’)
  2. $Status != (‘X’ || ‘Y’ || ‘Z’)

Will a basic course in javascript help increase accessibility when building expressions in SnapLogic?

Hi @NAl,

The second expression is wrong because that way if the Status is ‘X’ or ‘Y’ or ‘Z’ it will return true to both outputs.
You should change the second expression to $Status != "X" && $Status != "Y" && $Status != "Z", this way it will only evaluate to true if status is neither x, y nor z.
Also first expression should be: $Status == "X" || $Status == "Y" || $Status == "Z"

3 Likes

Hey @NAl ,

If you need to match the exact value of Status, than Jovanche’s expression will do the job, if you need to check if the Status field contains X,Y or Z, than you should go with the following expression:

$Status.contains('X') || $Status.contains('Y') || $Status.contains('Z')

and for the opposite situation, you can check the ‘First Match’ option, and enter true as a second expression.

3 Likes

Amazing! It’s now routing as expected. Thank you both for your inputs