简体   繁体   中英

IBM Watson Assistant: Expressions on dialog node condition using array?

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?

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 .

尝试:

$long_name_context_var >= 1 || $long_name_context_var <= 5

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM