How to get list collector values from custom table to catalog item variable

vinuthna16
Tera Contributor

Hi Team,

In custom table we have 2 fields
1.name
2.list collector referencing to user table

in catalog item
1.name
2.list collector- to user table

So, on change of name every time, the list collector should compare name with custom table and should dislay the names from custom list collector to variable list collector

Thanks,

Vinuthna

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

If the catalog item name variable is a reference to the custom table (where the name field is the display value) then you can start your onChange Catalog Client Script with a getReference to retrieve the value of the list collector field:

https://docs.servicenow.com/bundle/tokyo-api-reference/page/app-store/dev_portal/API_reference/Glide... 

 

Otherwise, if you're just matching the name value in the variable to the same name value in the custom table you need to use Glide Ajax to do the lookup and return the value of the list collector field.  This would work in the first scenario also

https://www.servicenow.com/community/developer-articles/glideajax-example-cheat-sheet-updated/ta-p/2... 

 

Once you have the value, via either method, which will be a comma-separated list of sys_ids from the sys_user table, you can simply use g_form.setValue to set the value of the list collector variable to the same names from the custom table, or if you are wanting to change the filter so that only these names are the ones available to be selected, then use this block of code:

var varName = 'v_users';// name of the list collector variable
var filterString = '';
 
//inside your GlideAjax or getReference callback function, set the answer or value = filterString variable, then
 try{ //Service Portal method
  var myListCollector = g_list.get(varName);
  myListCollector.reset();
  myListCollector.setQuery(filterString);
 }
 //Revert to Service Catalog method
 catch(e){
  window[varName + 'g_filter'].reset();
  window[varName + 'g_filter'].setQuery(filterString);
  window[varName + 'acRequest'](null);
 }

 

Hi ,

I tried this code but it is not working can you please send me the script include demo code once .

Thanks,

Vinuthna