Checking if string is in an array


#1

I am trying to start my piston off with defining an array of words, then I would like to use a restriction to not run the piston if the $currentEventValue is in the IgnoreList but I am getting an error.

string IgnoreList = ‘cat,dog,cow,horse’

only when
{$currentEventValue} is not any of {IgnoreList}

Error that I’m getting:
An error has occurred while subscribing: groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.startsWith() is applicable for argument types: (java.lang.String) values: [@]


#2

string is not an array. but you can define a string array. it should look like this string[] ignoreList. but, for now you cannot initialize this array in the define section. i know @ady624 has it in his plans to provide a function to init arrays in the define section and in other places, but probably busy with the webcore app dev for now.

try this instead:

only when
   indexOf('cat,dog,cow,horse', $currentEventValue) is -1