How to select multiple options in a list

ServiceNow Use6
Tera Guru

Hi,

My requirement is to have ability to select multiple options in a List of SIDs affected variable. Currently I am able to select only one value at a time. Kindly help.

 

0.png

 

1.png

 

2.png

 

Regards

Suman P.

 

14 REPLIES 14

ServiceNow Use6
Tera Guru

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

var ga = new GlideAjax('GetSIDsBySite');
ga.addParam('sysparm_name', 'getSIDs');
ga.addParam('sysparm_site', newValue);

ga.getXMLAnswer(function(response) {
if (response && response.trim() !== '') {
g_form.setValue('u_list_of_customers_affected', response);
} else {
g_form.clearValue('u_list_of_customers_affected');
}
});
}

var GetSIDsBySite = Class.create();
GetSIDsBySite.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getSIDs: function() {

var site = this.getParameter('sysparm_site');
if (!site) {
return '';
}

var sidList = [];

var gr = new GlideRecord('sn_install_base_sold_product');
gr.addQuery('u_location', 'IN', site);
gr.query();

while (gr.next()) {
sidList.push(gr.getUniqueValue());
}

return sidList.join(',');
}

});

ServiceNow Use6
Tera Guru

function onChange(control, oldValue, newValue, isLoading) {

// Do nothing on form load
if (isLoading) {
return;
}

// If Site is cleared → clear SIDs
if (!newValue) {
g_form.clearValue('u_list_of_customers_affected');
return;
}

// Call Script Include to fetch SIDs
var ga = new GlideAjax('GetSIDsBySite');
ga.addParam('sysparm_name', 'getSIDs');
ga.addParam('sysparm_site', newValue);

ga.getXMLAnswer(function(response) {
if (response && response.trim() !== '') {
g_form.setValue('u_list_of_customers_affected', response);
} else {
g_form.clearValue('u_list_of_customers_affected');
}
});
}

ServiceNow Use6
Tera Guru

function onChange(control, oldValue, newValue, isLoading) {

if (isLoading) return;

var site = g_form.getValue('u_location');
var serviceType = g_form.getValue('u_service_type');

// If Site OR Service Type is empty → clear SIDs
if (!site || !serviceType) {
g_form.clearValue('u_list_of_customers_affected');
return;
}

// Call Script Include
var ga = new GlideAjax('GetSIDsByFilter');
ga.addParam('sysparm_name', 'getSIDs');
ga.addParam('sysparm_site', site);
ga.addParam('sysparm_service_type', serviceType);

ga.getXMLAnswer(function(response) {
g_form.setValue('u_list_of_customers_affected', response);
});
}

var GetSIDsByFilter = Class.create();
GetSIDsByFilter.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getSIDs: function() {

var site = this.getParameter('sysparm_site');
var serviceType = this.getParameter('sysparm_service_type');

var sidList = [];

var gr = new GlideRecord('sn_install_base_sold_product');

// Filter by Site
gr.addQuery('u_location', 'IN', site);

// Filter by Service Type (product)
gr.addQuery('product', serviceType);

gr.query();

while (gr.next()) {
sidList.push(gr.getUniqueValue());
}

// 🔥 Important: return comma-separated sys_ids
return sidList.join(',');
}

});

ServiceNow Use6
Tera Guru

javascript: (function() {
var gr = new GlideRecord('sn_install_base_sold_product');
gr.addQuery('u_location', current.u_location);
gr.query();

var ids = [];
while (gr.next()) {
ids.push(gr.product.toString());
}

return 'sys_idIN' + ids.join(',');
})();

ServiceNow Use6
Tera Guru

javascript: (function() {

if (!current.u_location)
return 'sys_id=-1';

var gr = new GlideRecord('sn_install_base_sold_product');
gr.addQuery('u_location', current.u_location);
gr.query();

var ids = [];
while (gr.next()) {
ids.push(gr.product.toString());
}

if (ids.length == 0)
return 'sys_id=-1';

return 'sys_idIN' + ids.join(',');

})();