Client script for list collector variable only works on first item selected in the variable

sarahleighton
Tera Contributor

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 -

find_real_file.png

 

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

8 REPLIES 8

Mohith Devatte
Tera Sage
Tera Sage

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

Hi Mohith

Are you able to tell me how to implement the GlideAjax, please?

Thank you,

Sarah

SumanthDosapati
Mega Sage
Mega Sage

Hi @sarahleighton ,

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

Abhijit4
Mega Sage

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

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP