Hiding options in a list collector

Red
Giga Expert

How can you hide certain options in a list collector depending on the "read" setting for a variable?

1 ACCEPTED SOLUTION

Red
Giga Expert

I was able to do this using onChange of the field that will be used to do a query on what to show in the list collector field.

It's a bit of a process but it's the solution to my requirement.

But thanks to all those who responded to my post.

View solution in original post

11 REPLIES 11

Could you provide the OnChange script

Hi,

 

Here's the code I used. Hope it's clear for you:

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

//Type appropriate comment here, and begin script below

var collectorName = 'collector_target_name_here';
var ListCollectors = g_form.getValue('collector_that_will_change');
var filterString = 'question.sys_name=Field target label';
var addQuery = '';

var arrayList = ListCollectors.split(",");
var arrayLength = arrayList.length;
var qArray = [
['sys_id of list option 1', '^value=General option 1^ORvalue=General option 2^ORvalueLIKEGeneral option 3'],
['sys_id of list option 2', '^valueLIKEModified option 1^ORvalue=Modified option 2^ORvalue=Modified option 3'],
['sys_id of list option 3', '^valueLIKENew option 1'],
['sys_id of list option 4', '^valueLIKEOld option 1'],
['sys_id of list option 5', '^valueLIKESkillsets 1'],
['sys_id of list option 6', '^valueLIKEPersonal option 1']
];


if (ListCollectors == 'sys_id of list option 7') {
// 'Contact unsuccessful':
addQuery = '^value=Response option 1^ORvalue=Response option 2';
}
else {

//use this if only 1 option is selected
if (arrayLength == 1) {
if (arrayList == 'sys_id of list option 1'){
addQuery = qArray[0][1];
}

else if (arrayList == 'sys_id of list option 2') {
addQuery = qArray[1][1];
}

else if (arrayList == 'sys_id of list option 3') {
addQuery = qArray[2][1];
}

else if (arrayList == 'sys_id of list option 4') {
addQuery = qArray[3][1];
}

else if (arrayList == 'sys_id of list option 5') {
addQuery = qArray[4][1];
}

else if (arrayList == 'sys_id of list option 6') {
addQuery = qArray[5][1];
}

}


else {

// use this if more than 1 option is selected
for (i = 0; i < arrayList.length; i++) {
// get the size of the inner array
var innerArrayLength = arrayList[i].length;

if (arrayList[i] == 'sys_id of list option 1'){
useQuery = qArray[0][1];
}

else if (arrayList[i] == 'sys_id of list option 2') {
useQuery = qArray[1][1];
}

else if (arrayList[i] == 'sys_id of list option 3') {
useQuery = qArray[2][1];
}

else if (arrayList[i] == 'sys_id of list option 4') {
useQuery = qArray[3][1];
}

else if (arrayList[i] == 'sys_id of list option 5') {
useQuery = qArray[4][1];
}

else if (arrayList[i] == 'sys_id of list option 6') {
useQuery = qArray[5][1];
}

if ( i == 0 ) {
addQuery = useQuery;
}
else {
//replace value format of the first value in the string and concatenate with the default query value
addQuery = addQuery.concat(useQuery.replace(/^.{6}/g, '^ORvalue'));
}


}

 

}

}

filterString = filterString.concat(addQuery);


//Try Service Portal method
try{
var myListCollector = g_list.get(collectorName);
myListCollector.reset();
myListCollector.setQuery(filterString);
}

//Revert to Service Catalog method
catch(e){
//Hide the list collector until we've set the filter
g_form.setDisplay(collectorName, false);
setCollectorFilter();
}

function setCollectorFilter(){
//Test if the g_filter property is defined on our list collector.
//If it hasn't rendered yet, wait 100ms and try again.
if(typeof(window[collectorName + 'g_filter']) == 'undefined'){
setTimeout(setCollectorFilter, 100);
return;
}
//Find and hide the filter elements (optional)
//Simple method for items with only one list collector
//$('ep').select('.row')[0].hide();
//Advanced method for items with more than one list collector (more prone to upgrade failure)
//var el = $('container_' + g_form.getControl(collectorName).id).select('div.row')[0].hide();

//Reset the filter query
window[collectorName + 'g_filter'].reset();
window[collectorName + 'g_filter'].setQuery(filterString);
window[collectorName + 'acRequest'](null);
//Redisplay the list collector variable
g_form.setDisplay(collectorName, true);

}


}