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

Hi,



You've to put the sys_id of the "Item A" in place of the name.



or you can try, and check the name of your record in the if using a gliderecord:


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


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


for (var i=0; i < arrayList.length; i++) {  


  }



Best Regards



Alexandre Herrero



EDIT: Try to display what is returned by current.variables.list_collector.getDisplayValue(); ---> so you will know what condition to do ---> for example: gs.log("Test: " + current.variables.list_collector.getDisplayValue());


Hi Alexandre -



The return is the text display for the items, so example in the log it is in fact returning "Item A"



With that, I think your code you provided initially should work....



What am I missing?



Thanks,


Shane


Hi,



Sometime it's just a problem of a "toString()" missing.



You can try to take the values like that: current.variables.list_collector.toString();



You should be able to make it work.



Best Regards



Alexandre


Alexandre -



The code you used works great with the toString(), I just needed to be searching on the sys_id of those objects. Works fine now once I put that in the script.



Thank you,


Shane


If you are searching on the sys_id, there is no need to break it into an array.   The simplest way to do it is:



answer = (function() {


if (current.variables.list_collector.toString().indexOf("sys id you are looking for") > -1) {


  return "yes";


}


return "no";


})();




It will return "yes" if the sys_id is found in the comma-separated string of sys_ids that the list collector stores its values in.