How to set a default value for a slush bucket variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2016 06:54 AM
I have a use case where I need to set a slush bucket of cmdb_ci_systems to a list based upon a filter.
I seem to have succeeded in getting the filter to work and it populates the left bucket with the correct list of system.
But I can't seem to get the values to move to the right.
Here's the code from my onLoad catalog client script. The final result is that the left bucket is populated with list of systems and the right bucket has '--none--'.
Thanks to the jslog statements, I confirmed that the setDefaultValue() function did run to completion.
Can anyone say where I've gone wrong?
function onLoad() {
//Apply a default filter to the list collector variable
var collectorName = 'server_list';
var filterString = 'GOTOattributes>=hezpadmin';
//Hide the list collector until we've set the filter
g_form.setDisplay(collectorName, false);
setCollectorFilter();
setDefaultValue();
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 the filter elements
var fil = gel('ep');
//Hide the filter elements by un-commenting the following lines
/*fil.rows[0].style.display = 'none';
fil.rows[1].style.display = 'none';
fil.nextSibling.rows[0].style.display = 'none'; //Filter description text*/
//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);
}
}
// http://www.servicenowguru.com/scripting/client-scripts-scripting/move-list-collector-options/
function setDefaultValue() {
jslog('entering setDefalutValue');
//Name of variable to move options from
var varName = 'server_list';
var leftBucket = gel(varName + '_select_0');
var rightBucket = gel(varName + '_select_1');
var selectedOptions = leftBucket.options;
//Get an array of all option IDs to move
var selectedIDs = new Array();
var index = 0;
for(var i = 0; i < selectedOptions.length; i++){
selectedIDs[index] = i;
index++;
}
//Move all returned options from right to left bucket and sort the results
//Switch 'rightBucket' and 'leftBucket' to move from left to right
//moveSelectedOptions(selectedIDs, rightBucket, leftBucket, '--None--');
//moveSelectedOptions(selectedIDs, leftBucket, rightBucket, '--None--');
moveOptionAndSort(leftBucket, rightBucket, '--None--', selectedIDs, '--None--');
//Sort the resultant options in the bucket
//sortSelect(rightBucket);
jslog('exiting setDefaultValue');
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2016 08:38 AM
Steve,
Replace your code in function setDefaultValue() with the below code. I believe this should work
http://www.servicenowguru.com/scripting/client-scripts-scripting/move-list-collector-options/
var varName = 'server_list';
var leftBucket = gel(varName + '_select_0');
var rightBucket = gel(varName + '_select_1');
if(rightBucket.options.length == 1 && rightBucket.options[0].text == '--None--'){
rightBucket.options.length = 0;
}
var selectedOptions = leftBucket.options;
//Get an array of all option IDs to move
var selectedIDs = new Array();
var index = 0;
for(var i = 0; i < selectedOptions.length; i++){
selectedIDs[index] = i;
index++;
}
//Move all returned options from right to left bucket and sort the results
//Switch 'rightBucket' and 'leftBucket' to move from left to right
moveSelectedOptions(selectedIDs, leftBucket, rightBucket, '--None--');
//Sort the resultant options in the left bucket
sortSelect(rightBucket);
Thanks,
Abhinay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2016 10:10 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2017 02:13 AM
Hi,
I would like to do the same with glide_list variable.
I first created a list collector (slush bucket) variable
With your code I was able to define a filter for the left side and move one item to the right side.
Then I add glide_list attribute to my variable and this doesn't work anymore
Any idea to set value of a glide_list variable ?