- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2013 04:22 PM
I've seen a lot about how to default the filter for a list collector (pre-filling the "left side"), but I can't seem to find anything about defaulting the selected values of a list collector (to pre-fill the "right side"). The closest I came was unfortunately a dead end: How to pre-populate a collection list?
In that post, it was suggested that you should be able to set list collector selections by using the standard g_form.setValue() method (http://wiki.servicenow.com/index.php?title=GlideForm_%28g_form%29#setValue), but I can't get that to work:
// This should work, according to the Wiki: g_form.setValue('watch_list', '1', 'Michael McCall'); // assuming that '1' were actually my sys_id value // However, having this in a catalog client script does not work: g_form.setValue('requested_users', '1', 'Michael McCall'); // assuming that I have a list collector variable named "requested_users"
Is it just not possible to programmatically set list collector values, or is there a special method for doing so? (I might guess it has something to do with the g_filter object, but I can't find any information about that object beyond the setFilter() method.)
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2013 11:17 AM
List collector's are very different.
I think Mark Stanger's post is probably the easiest to follow;
http://www.servicenowguru.com/scripting/client-scripts-scripting/move-list-collector-options/
the tl;dr is that there are two functions available
and
moveSelectedOptions(selectedIDs, rightBucket, leftBucket, '--None--')
sortSelect(leftBucket)
These should let you move stuff around, and re-sort the left or right objects.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2016 12:53 AM
Yogesh ,
PFB.
Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.
//Name of variable to move options from
var varName = 'YOUR_VARIABLE_NAME_HERE';
var leftBucket = gel(varName + '_select_0');
var rightBucket = gel(varName + '_select_1');
var selectedOptions = rightBucket.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--');
//Sort the resultant options in the left bucket
sortSelect(leftBucket);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2017 12:17 AM
what is this _select_0 and _select_1;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2017 12:53 AM
this ain't working .. i put user table on list collector to autopopulate current logged in user on left side of list collector. please help me on this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2017 02:54 AM
Hello, this is good but doesnt work on service portal
Can you advise how to get that particular example working in service portal ?
Thank you
/Petr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2018 12:56 PM
In Service Portal, you just pass the list selector a sys_id or a list of sys_ids that you want displayed. For example, if the variable name of the list selector is 'selector', you could do something like this:
g_form.setValue('selector', ['sys_id_1', 'sys_id_2', ... , 'sys_id_n']);