Client script for list collector variable only works on first item selected in the variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2022 01:07 AM
Hi all
I've created a script that displays a variable on a form, based on a choice selected in a List Collector variable. The only problem is, the script only seems to run on the first choice selected in the list collector, but we need it to work on all selections.
This is the script -
At the moment, if the first item a user selects in the list collector has the u_generic_class of FURNITURE, then the item_damaged variable displays on the form, as required. But if the user selects an item that doesn't have the u_generic_class of FURNITURE first, but then selects a second item in the list collector that does have the u_generic_class of FURNITURE, the variable doesn't display, but we want it to. If any item selected in that list collector has the u_generic_class of FURNITURE, we want the variable to show. Does anyone know how this can be achieved?
Thanks very much in advance
Sarah
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2022 07:20 AM
Hi Abhijit
Are you able to tell me how to implement the GlideAjax, please?
Thank you,
Sarah

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2022 06:03 AM
Hi
You can modify client script as below :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax("ScriptIncludeName"); //give your client callable script include name which you are going to create in next steps
ga.addParam('sysparm_name', 'getItemDetails');
ga.addParam('sysparm_val', value);
ga.getXML(callback);
}
function callback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer == 'yes')
{
g_form.setDisplay('item_damaged', true);
g_form.setMandatory('item_damaged', true);
}
else
{
g_form.setMandatory('item_damaged', false);
g_form.setDisplay('item_damaged', false);
}
}
Add below function in a client callable script include
getItemDetails: function() {
var answer;
var value = this.getParameter('sysparm_val');
var gr = new GlideRecord("u_standard_items");
gr.addEncodedQuery("sys_idIN"+value);
gr.addQuery('u_generic_class', 'FURNITURE'); //check backend value for furiture
gr.query();
if(gr.next()) {
answer = 'yes';
}
else
{
answer = 'no';
}
return answer;
},
Mark as correct and helpful if it solved your query.
Regards,
Sumanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2022 03:37 AM
Did you try the above solution?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2022 07:32 AM
Hi,
Replace line gr.addQuery("sys_id",value) with gr.setEncodedQuery("sys_idIN" + value);
Replace line if(gr.next()) to while(gr.next());
Refer below link for more details:
https://developer.servicenow.com/dev.do#!/reference/api/rome/client/c_GlideRecordClientSideAPI
Palani