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

Subhajit1
Giga Guru

Hi Shane,


You can try using this:-


var liststr = current.variables.list_collector.toString();


var listarray = liststr.split(',');




for(index=0; index<listarray.length; index++)


{


//You Validation Code on listarray[index]


}




Thanks,


Subhajit


I have tried the following:



var liststr = current.variables.list_collector.toString();


var listarray = liststr.split(',');


for(index=0; index<listarray.length; index++)


      {


      if ((listarray[index] == "Item A") || (listarray[index] == "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...