how to mapped the values to list collector field using script

MH3
Tera Contributor

I am returning some group users array inside script include using this line. 

return 'sys_idIN' + users.toString();

how to mapped them inside list collector field on client script.

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

This is an example of an onChange Catalog Client Script that calls a Script Include via Glide Ajax.  The use case here is a group name is selected in a reference field, then the List Collector should only show the users that are members of that group, not all users as is the initial filter.  The SI returns the same format you are using, then the rest of the script shows how to update the List Collector filter to display these records in the Available box.  This works in Service Portal and the Service Catalog / Native UI:

var varName = 'v_assets';// name of the list collector variable
var filterString = '';
 
var apps = new GlideAjax('AssetFilter');// script include
//... variables and values to pass to script include...
apps.getXML(assetList);
 
function assetList(response) {
 var answer = response.responseXML.documentElement.getAttribute("answer");
 filterString = answer;
 
 try{
  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);
 }
}

If what you are trying to do is set the value of a List Collector to the records returned in the array, then you can just set the variable value to the comma-separated list of sys_ids without the 'sys_idIN'.

 

View solution in original post

1 REPLY 1

Brad Bowman
Kilo Patron
Kilo Patron

This is an example of an onChange Catalog Client Script that calls a Script Include via Glide Ajax.  The use case here is a group name is selected in a reference field, then the List Collector should only show the users that are members of that group, not all users as is the initial filter.  The SI returns the same format you are using, then the rest of the script shows how to update the List Collector filter to display these records in the Available box.  This works in Service Portal and the Service Catalog / Native UI:

var varName = 'v_assets';// name of the list collector variable
var filterString = '';
 
var apps = new GlideAjax('AssetFilter');// script include
//... variables and values to pass to script include...
apps.getXML(assetList);
 
function assetList(response) {
 var answer = response.responseXML.documentElement.getAttribute("answer");
 filterString = answer;
 
 try{
  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);
 }
}

If what you are trying to do is set the value of a List Collector to the records returned in the array, then you can just set the variable value to the comma-separated list of sys_ids without the 'sys_idIN'.