- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2018 07:20 AM
Hello All,
I am trying to set value of list collector in selected while page is loading,
Below is my code,
function onLoad() {
//Type appropriate comment here, and begin script below
var varName = 'update_group_test';//Variable name
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 = [];
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);
}
I referred below ServiceNow guru link ,
https://www.servicenowguru.com/scripting/client-scripts-scripting/move-list-collector-options/
Please help
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2018 07:46 AM
than easiest way will be adding default value on list collector variable. If is reference field than sys_id of record. if more than 1 record than separated by comma.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2018 07:46 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2018 01:47 AM
Hello Mike,
Thanks for your help on this!!!
I have one more question,
I want this List collector value set on change of one of field from my form, but this time it's not default selection it should be dynamic on change that field value.
Thank you!!!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2019 10:30 PM
Hi Mike,
I see you have "Default Value Script" field. But I can't find the field. Is that your custom field?
Thanks,
Koji
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2018 07:48 AM
I believe this code sample will not apply to what you are attempting to accomplish.
I could be wrong but I think what this code is for is to multiselect options in a slushbucket.
I think what you want to accomplish is to just simply set a default value on load. If you have the sys_ids of the records you want selected, Im pretty sure it just has to be in the format of a comma delimited string and use g_form.setValue().
This has not been tested but may give you a start
// Default sys ids
var defaultSelectedOptions = ['asdkf2klk23lk23','asdkf2klk23lk23','asdkf2klk23lk23'];
// Set the value of your field
g_form.setValue('FIELDNAME', defaultSelectedOptions.toString());