one catalog variable list population based on the selection of another catalog variable.

Ramya95
Tera Contributor

The requirement is we have  catalog variable-1  which reference to user table. Another catalog variable-2 which is list collector type variable that also references to user table. Condition is whenever we select the any user from the catalog variable-1, then the catalog variables -2 should populate the list of users where the users have manager( which is the selected user  in  catalog variable1.)

Eg: if i selected user as Alex in catalog variable 1 , then list of users who have Alex as manager should be shown in Catalog variable 2

This should work in both employee center portal and native UI.

Please provide a solution , how this can be implemented.

2 REPLIES 2

Gustav Aldenbra
Kilo Sage

Hi @Ramya95,

 

This can be implemented by using an onChange client script on the first variable to call a Script Include via GlideAjax, which returns users who have the selected user as their manager, and then populates the list collector with those users

I have included a code example you could try, not testing in my own instance but should work.

Script Include example:
Make sure Client callable is true

var GetSubordinates = Class.create();
GetSubordinates.prototype = Object.extendsObject(AbstractAjaxProcessor, {

  getUsersByManager: function() {
    var managerId = this.getParameter('sysparm_manager_id');
    var ids = [];

    var gr = new GlideRecordSecure('sys_user');
    gr.addQuery('manager', managerId);
    gr.query();

    while (gr.next()) {
      ids.push(gr.getValue('sys_id'));
    }

    return ids.join(',');
  }

});

 

Client script example:

function onChange(control, oldValue, newValue, isLoading) {
  if (isLoading || !newValue) return;

  g_form.setValue('variable_2', ''); // Clear existing values

  var ga = new GlideAjax('GetSubordinates');
  ga.addParam('sysparm_name', 'getUsersByManager');
  ga.addParam('sysparm_manager_id', newValue);
  ga.getXMLAnswer(function(response) {
    g_form.setValue('variable_2', response);
  });
}

 

Hi @Gustav Aldenbra 
Instead of auto populating the values in the variable, is it possible to lookup the records which can be selected.