Checking a List Collector for a Value?

Paula Cullen
Kilo Guru

Hi All,

Need some help with scripting please.

I have a list collector with a long list of left bucket values. I also have a workflow in which I want to check for a chosen rightbucket option. If there's one particular option in the list of options chosen by the user, I have to send a second approval. That part I have working just fine. The part I'm having a problem with is checking the options chosen in the list collector for the single value I want. I've found lots of bits of code that I've tried to cobble together without success.

This is what I have. It's in an IF SCRIPT in the workflow so I can get a yes or no for the workflow...

function ifScript() {
var varName = current.variables.ctmsaccess_responsibilities;
var opp = 'd368d049f01210848484ae45a01accba';
var rightBucket = gel(varName + '_select_1');
var selectedOptions = rightBucket.options;

//Get an array of all option IDs
var selectedIDs = new Array();
var index = 0;
for(var i = 0; i < selectedOptions.length; i++){
selectedIDs[index] = i;
index++;
//check to see if the array contains the value
if (opp in index) {
return 'yes';
}
return 'no';
}
}

I need some guidance or a simpler way to do this, I have to get this finished asap.

Thanks!

4 REPLIES 4

Jim Coyne
Kilo Patron

Because a List Collector stores the selected items as a comma-separated list of sys_ids, you can use the following to see if a sys_id exists in that list:



answer = ifScript();
function ifScript() {
if (current.variables.applications.toString().indexOf("82992eb60ad337024fbb6d06a866c636") >-1) {
return 'yes';
}
return 'no';
}


Take a look at the "Test Catalog Item" catalog item and workflow in demo08 for an example.


how to search from list collector in a table?

Sorry, but I do not understand the question

Paula Cullen
Kilo Guru

Wonderful, Jim. Thank you!