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 01:11 AM
Hello,
In an onchange script we are not supposed to use glide record its not a best practice instead of that you have to use GldieAjax to achieve this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2022 07:20 AM
Hi Mohith
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-20-2022 03:23 AM
Hi
1) You cannot use GlideRecord in client script
2) Under the call back function change the loop from if to while
3) Change gr.addQuery line to gr.addQuery("sys_idIN"+value);
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-20-2022 03:34 AM
We are not supposed to use GlideRecord in client script, instead use glideajax.
Your main problem is you should be using below query,
gr.addQuery("sys_idIN"+value);
Also, in your callback function you should be using while instead of if as shown below,
while(gr.next())
Use GlideAjax and implement above logic in script include.
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Community Rising Star 2022
Regards,
Abhijit
ServiceNow MVP