List collector set value not working properly

Kalpesh13
Kilo Contributor

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

1 ACCEPTED SOLUTION

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. 

find_real_file.png

View solution in original post

8 REPLIES 8

Mike Patel
Tera Sage

Are you trying to do this on portal side?

Hello Mike,

 

I am trying to do on both sides on portal and also from backend.

 

Thanks,

Kalpesj

Are you trying to set default selection to right when it's loaded than user can remove it if they don't want it?

Kalpesh13
Kilo Contributor

Yes, I am trying to set up default selection of right bucket while loading the form. after that users can remove if they want to do.