Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Service catalog variable for list of managers

Ryan M
Giga Guru

We are trying to create a catalog item variable to display the list of users that are managers.  Is there a build in variable type that will let me create a reference for the managers field?

1 ACCEPTED SOLUTION

If it is as easy as you make it sound please feel free to correct me.  I'm a relatively new ServiceNow admin. I don't see a simple solution to only showing users that are listed as a manager.  I looked into how advanced conditions work and ended up making a script include that returns a distinct list of sys_ids from the manager column on sys_user.  

In the advance qualifier:
javascript:getListOfManagers();

Script include:
function getListOfManagers() {
    var mgr_sys_ids = [];
    
    var gr = new GlideAggregate('sys_user');
    gr.groupBy('manager');
    gr.query();
    
    while (gr.next()) {
        mgr_sys_ids.push(gr.manager.sys_id);
    }
    
    return 'sys_idIN' + mgr_sys_ids.join(",");
}

View solution in original post

4 REPLIES 4

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Ryan,

Nothing OOTB. You can do this via Reference qualifier.

https://docs.servicenow.com/bundle/orlando-platform-administration/page/script/server-scripting/conc... 

- Pradeep Sharma

If it is as easy as you make it sound please feel free to correct me.  I'm a relatively new ServiceNow admin. I don't see a simple solution to only showing users that are listed as a manager.  I looked into how advanced conditions work and ended up making a script include that returns a distinct list of sys_ids from the manager column on sys_user.  

In the advance qualifier:
javascript:getListOfManagers();

Script include:
function getListOfManagers() {
    var mgr_sys_ids = [];
    
    var gr = new GlideAggregate('sys_user');
    gr.groupBy('manager');
    gr.query();
    
    while (gr.next()) {
        mgr_sys_ids.push(gr.manager.sys_id);
    }
    
    return 'sys_idIN' + mgr_sys_ids.join(",");
}

Hello Ryan,

Yes, you are right. You need a script include that returns a sys_ids of manager. Please feel free to share the script  in case it is not working.

 

- Pradeep Sharma

It's working great, thanks for pointing me in the right direction.  I edited my previous reply with the code.