Parsing list collector selections

shane_holland
Mega Contributor

Hi everyone -

 

I need to check for a particular selection from a list collector in a Service Catalog item. In the workflow, I can get the values (which are comma delimited by default) like:

 

current.variables.list_collector.getDisplayValue()

 

What I need to do is when generating tasks, I need to create a task if a certain item is in the list collector. In the workflow, how can I parse the selections and look for a particular item?

 

Thanks,

Shane

1 ACCEPTED SOLUTION

Hi,



Not tested, but in an "if" activity, you can try something like (or remove the toString):



var arrayUtil = new ArrayUtil();


var list = current.variables.list_collector.getDisplayValue().toSring();


var arrayList = list.split(",");


if (arrayUtil.contains(arrayList, "youritem")) {


    answer="yes";


} else {


    answer="no";


}



Best Regards


View solution in original post

11 REPLIES 11

AlexandreHerrer
Kilo Expert

Hi,



There are several possibilities here, I think the easiest would be to do an "if" with as scripted condition that check if this item is in the list. (of if condition true, create task, if not, go to next step)



Best Regards


Oh, right, I understand that I just do not know the code to do so


Hi,



Not tested, but in an "if" activity, you can try something like (or remove the toString):



var arrayUtil = new ArrayUtil();


var list = current.variables.list_collector.getDisplayValue().toSring();


var arrayList = list.split(",");


if (arrayUtil.contains(arrayList, "youritem")) {


    answer="yes";


} else {


    answer="no";


}



Best Regards


I have tried the following with your code:



var arrayUtil = new ArrayUtil();


var list = current.variables.list_collector.getDisplayValue();


var arrayList = list.split(",");


if (arrayUtil.contains(arrayList, "Item A") || arrayUtil.contains(arrayList, "Item B")) {


    answer="yes";


} else {


    answer="no";


}



I am selecting Item A as one of the selections in the list collector, but the code is returning result No...