List collector not working in the Native UI.

JLeong
Mega Sage

Hi All,

I have the below client script to move list collector values from left to right. It is working in the portal but in the native UI the filter is not working, it is transferring everything from left to right. Could someone please check and let me know how to fix it.

Thanks in advance.

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

g_form.clearValue('sftp_sites_to_update');

if (newValue !== '') {
var parm = '';
if (window === null)
parm = 'portal';
else
parm = 'native';
}

var accntsList = 'sftp_sites_to_update'; // variable name of the List Collector
var filterString = 'u_active=true^owned_by=' + newValue;
alert('filterString - ' + filterString);
// filter list collector to only show the accounts owned by the current user (left side)
// reset the filter (left side) based on the above filterstring

if (parm == 'portal') {
var myListCollector = g_list.get(accntsList);
myListCollector.reset();
myListCollector.setQuery(filterString);
g_form.hideFieldMsg('sftp_current_owner', true);
g_form.showFieldMsg('sftp_current_owner', 'Please wait... searching for SFTP Account(s)...');
} else {
window[accntsList + 'g_filter'].reset();
window[accntsList + 'g_filter'].setQuery(filterString);
window[accntsList + 'acRequest'](null);
g_form.hideFieldMsg('sftp_current_owner', true);
g_form.showFieldMsg('sftp_current_owner', 'Please wait... searching for SFTP Account(s)...');
}

//now populate the Service Portal variable
if (parm == 'portal') {
var ajax = new GlideAjax('SFTPutil');
ajax.addParam('sysparm_name', 'getSFTP_Accnts');
ajax.addParam('sysparm_owner', newValue);
ajax.getXML(populateValues);

} else {
var leftBucket = gel(accntsList + '_select_0');
var rightBucket = gel(accntsList + '_select_1');
var selectedOptions = leftBucket.options;

//Get an array of all option IDs to move
var selectedIDs = new Array();
alert('selectedIDs ' + selectedIDs);
var index = 0;
for (var i = 0; i < selectedOptions.length; i++) {
selectedIDs[index] = i;
index++;
}
rightBucket.options.length = '0';
moveSelectedOptions(selectedIDs, leftBucket, rightBucket);
sortSelect(rightBucket);
g_form.hideFieldMsg('sftp_current_owner', true);
if (selectedIDs == 0) {
g_form.showFieldMsg('sftp_current_owner', 'No SFTP Account(s) found!');
}
}

function populateValues(response) {
g_form.hideFieldMsg('sftp_current_owner', true);
var answer = response.responseXML.documentElement.getAttribute("answer");
//alert('answer = ' + answer);

if (answer == '||') {
g_form.showFieldMsg('sftp_current_owner', 'No SFTP Account(s) found!');
}
var arr = answer.split('||');
//arr[1] has the sys_id of the accountID
//arr[0] has the display name of the accountID
g_form.setValue('sftp_sites_to_update', arr[1], arr[0]);
}
}

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can refer below blog for help for similar requirement

https://community.servicenow.com/community?id=community_blog&sys_id=a60c397edb04dc1c190dfb24399619b1

Client Script: Ensure "Isolate Script" field is set to false for onChange Catalog Client Script on that Variable

  1. The field Isolate Script is not present on the form view
  2. From the list layout it can be added and set to false
  3. By default it is true

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

10 REPLIES 10

Harsh Vardhan
Giga Patron

just confirming, did you set  "Isolate Script" field to false in your client script?

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can refer below blog for help for similar requirement

https://community.servicenow.com/community?id=community_blog&sys_id=a60c397edb04dc1c190dfb24399619b1

Client Script: Ensure "Isolate Script" field is set to false for onChange Catalog Client Script on that Variable

  1. The field Isolate Script is not present on the form view
  2. From the list layout it can be added and set to false
  3. By default it is true

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Thanks Ankur!!!

may i know what was the issue, so it will be helpful for other user who will see this thread in future.