GlideForm don't set list collector value properly with GlideAjax response

jerrypeng02
ServiceNow Employee
ServiceNow Employee

The current problem is: I want to set the list collector value with user list I get back from GlideAjax response in my onChange catalog client script. The `userList` I got back and display on the form is actually the same as my hardcoded list for user sys ids. But when I set the hardcoded value to the users field of the form, it only appears 2 users on the right of the slushbucket. What is going on and how do I resolve this problem?

Screenshot 2024-08-29 at 9.47.29 AM.png

Below are the code:

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

var gUrl = new GlideURL();
gUrl.setFromCurrent();
var businuessLocationId = gUrl.getParam("sysparm_parent_id");

var responsibilityType = newValue;
var ga = new GlideAjax('GetResponsibilityMemberUsers');
ga.addParam('sysparm_name', 'getUsers'); // Function name should be provided
ga.addParam('sysparm_bl', businuessLocationId);
ga.addParam('sysparm_type', responsibilityType);
ga.getXMLAnswer(callback);

}

function callback(resp) {
var userList = resp;
g_form.clearValue('users');
// g_form.setValue('users', userList);
g_form.addInfoMessage('users ' + userList);
g_form.setValue('users', '1d6705835b2506100c7609f8e281c73f,4a826bf03710200044e0bfc8bcbe5d7f,36d581035b2506100c7609f8e281c7de,56826bf03710200044e0bfc8bcbe5dca');
}
1 ACCEPTED SOLUTION

If the property doesn't exist the results are limited to 100.  Create a property with that name and set it to 200, or 500, or whatever.  Updating the filter, either via reference qualifier or a script will limit the number of records on the left, thereby ensuring that the intended records are present.  In this case, it seems like it would be best to use the same string of sys_ids returned by the GlideAjax, then you would precede it with 'sys_idIN' before using it to update the filter, then lastly update the variable value:

function callback(resp) {
    var userList = resp;
    var varName = list_collector_variable_name;
    var filterString = 'sys_idIN' + resp;
    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);
    }
    g_form.setValue('users', userList);
}

 

View solution in original post

7 REPLIES 7

If the property doesn't exist the results are limited to 100.  Create a property with that name and set it to 200, or 500, or whatever.  Updating the filter, either via reference qualifier or a script will limit the number of records on the left, thereby ensuring that the intended records are present.  In this case, it seems like it would be best to use the same string of sys_ids returned by the GlideAjax, then you would precede it with 'sys_idIN' before using it to update the filter, then lastly update the variable value:

function callback(resp) {
    var userList = resp;
    var varName = list_collector_variable_name;
    var filterString = 'sys_idIN' + resp;
    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);
    }
    g_form.setValue('users', userList);
}

 

Got it, finally it works and thank you so much!

You are welcome!