
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2014 05:16 AM
I have a catalog task with a UI policy, if Other is selected in the list collector a text box appears. If someone then choose a different request type that does not have the list collector the text box still appears. For a drop down I can run the following code to set the drop down back to --None--. Is there similar code I can use in a client script for a list collector. This does not appear to work for a list collector.
g_form.setValue('changetype', '', '--None--');
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2014 05:47 AM
I think this is actually what you're after.
» How to Move List Collector Options with a Catalog Client Script in Service-now
It's designed to work on the front-end catalog form though so I'm not sure how it will work on a back-end catalog task. In general, you'll have a much better experience with service catalog variables if you refrain from this type of manipulation on the back-end tasks. They're just not designed with the same capabilities there.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2014 05:58 AM
That was perfect thanks Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2015 05:10 AM
Hi Mark
Can you please suggest on the below code, On change of the group name, form is appending group members in the "Group Members" list collector instead of first clearing out names from previous group and then populating with members of the new group.
Steps to reproduce:
1.) click the SNOW Group Administration" SC Item in the service catalog
2.) choose "Change existing" in the "Group Request Type" field
3.) start typing a group name in the "Group Name" , such as "service_mgmt" and tab out of field
4.) observe members appear in the list collector
5.) go back to "Group Name" field, enter a DIFFERENT group, eg. "SNOW DEV"
6.) observe members from both SERVICE_MGMT & SNOW DEV are in the list of group members.
Group members should FIRST clear from the list collector and then enumerate with ONLY group members for the currently selected group.
#Client Script onChange()
function onChange(control, oldValue, newValue, isLoading) {
if (oldValue != newValue){
var nam = [];
var ids = [];
var name = g_form.getValue('nname');
nam = GroupMembers(name);
ids = GroupMembersID(name);
var varName = 'members';
var rightSide = gel(varName+'_select_1');
var leftSide = gel(varName+'_select_0');
var checked;
for (var i = 0; i < ids.length; i++){
checked = false;
for (var h = 0; h < leftSide.length; h++){
if(ids[i] == leftSide.options[h].value) {
checked = true;
leftSide.options[h].selected = true;
break;
}
}
if (!checked) {
h++;
leftSide[h] = new Option(nam[i], ids[i]);
leftSide.options[h].selected = true;
}
}
// alert("Check");
moveOptionAndSort(leftSide, rightSide, '—None—', [], '—None—');
for (i = 0; i < rightSide.length; i++){
rightSide.options[i].selected = false;
}
membersg_filter.reset();
membersg_filter.setQuery('active=true^nameISNOTEMPTY');
membersacRequest(null);
// alert("check1");
}
}
function GroupMembers(group) {
var name ='';
var nam = [];
var sb = new GlideRecord('sys_user_grmember');
sb.addQuery('group',group);
sb.query();
while(sb.next()){
name = sb.user;
var sz = new GlideRecord('sys_user');
sz.addQuery('sys_id',name);
sz.query();
if(sz.next()){
nam.push(sz.name);
}
}
return nam;
}
function GroupMembersID(group) {
var id = [];
var sb = new GlideRecord('sys_user_grmember');
sb.addQuery('group',group);
sb.query();
while(sb.next()){
id.push(sb.user);
}
return id;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2015 08:35 AM
Hello Mark,
I have tried the same code, which was given in SNGuru link. But the code is executing before Left-Bucket gets loaded with our Filter query. So it is moving the null options from left-bucket to right-bucket. (Because by default we have some number of null value options. Once the data loaded to the left-bucket, those null options will be override). By DOM inspect you can see that.
Before the data loaded to left-bucket :
<option value="f73c6b9c6f0446805f4275fabb3ee464"></option>
After the code exceuted, it was moved those null option to right-bucket :
<option value="f73c6b9c6f0446805f4275fabb3ee464">null</option>
So as a result you can see the moved items in right-bucket with gray color :
If you notice, you can find that field's mandatory indicator changed to "Green". Normally this will happen once any option moved from left to right only.
Is there anyway to stop the process until the data loaded to left-bucket ?
Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2015 08:48 AM
Hello Krishnasundar,
Are you using this as an on load script? I have only used this as an on change script. If the user changes the request type (in our case) that the list collector is not needed for and it allows me to hide fields that may have been made visible due to something they picked from the list collector.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2015 02:00 AM
Hi Brain,
I told about that move the options from left to right. Hiding the filter & Clearing the right-bucket is working fine.
But to move the options from left-bucket to right-bucket, I have used the below code. This is moving the above mentioned null options from left to right. After this execution only, our actual data filled in the left-bucket.
This is my onChange script :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var collectorName = '';
var filterString = '';
if (newValue != '') {
//Apply a filter to the list collector variable
collectorName = 'temp_collector';
filterString = 'ci_assigned_to=' + newValue;
//Find the filter elements
var fil = gel('ep');
//Hide the filter elements
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
eval(collectorName + 'g_filter.reset()');
eval(collectorName + 'g_filter.setQuery("' + filterString + '")');
eval(collectorName + 'acRequest(null)');
// Gets the right column of the List Collector
var rightBucket = gel(collectorName + '_select_1');
// Loops through all the selected entries and remove them
while (rightBucket.firstChild) {
if (rightBucket.firstChild != null && rightBucket.firstChild != '') {
rightBucket.removeChild(rightBucket.firstChild);
}
}
//Name of variable to move options from
var leftBucket = gel(collectorName + '_select_0');
var rightBucket = gel(collectorName + '_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, leftBucket, rightBucket, '--None--');
//Sort the resultant options in the left bucket
sortSelect(rightBucket);
}
}
I have placed the "moveSelectedOptions" function after the list-collector filter. So it should get executed after the data loaded into the left-bucket. But unfortunately it is executing before the data loaded into the left-bucket. (Need help in line no : 41 to 64)
Any idea ??