Reputation: 199
For IBM Watson Assistant and a dialog node condition I want to check if the context variable long_name_context_var has one of the values 1,2,3,4,5. The normal way would be
$long_name_context_var == 1 || $long_name_context_var == 2 ||
$long_name_context_var == 3 || $long_name_context_var == 4 ||
$long_name_context_var == 5
But it is visually too long. Thus, I want to shorten it. I tried to use JSONArray.contains and Array literals as
[1,2,3,4,5].contains($long_name_context_var)
but failed.
Doesn't the node condition support array literals? Or would it give a syntax error?
Upvotes: 1
Views: 1179
Reputation: 17166
The conditions on a dialog node in IBM Watson Assistant support SpEL-based expressions. This includes the contains function on JSON arrays.
Have you enabled debugging in the Try it to see the value of the context variable? I assume your node works with the "visually too long" expression. Is the type of the context variable a string or a number? Try using
["1","2","3","4","5"].contains($long_name_context_var)
What definitely works is to assign the array to a context variable (in my test testme in the context editor in Try it) and then use the following expression:
$testme.contains("3")
Else you could try the indexOf function.
Upvotes: 1
Reputation: 10717
Try with:
$long_name_context_var >= 1 || $long_name_context_var <= 5
Upvotes: 0