We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Listing all users who report to the current user

nathandanek
Tera Contributor

Hello all,

 

I am attempting to use the dynamic choice input in the virtual agent and I want it to present the user using the virtual agent a list of all of their direct reports using the sys_user table and matching the 'manager' field with the current users name. This is the script I have written, but when I impersonate someone with direct reports (I am one of them), it tells me that they do not have any direct reports.

 

(function execute(table) {
    var options = [];
    var emp = new GlideRecord(table);

    emp.addActiveQuery();
    emp.addQuery('manager',gs.getUserName());
    emp.query();

    while(emp.next()){
        options.push(emp.getUniqueValue());
    }
    
    return options;
    
})(table)

 Any help would be appreciated! Thanks! 

5 REPLIES 5

harshav
Tera Guru

 

    var options = [];
    var emp = new GlideRecord('sys_user');
    emp.addActiveQuery();
    emp.addQuery('manager',gs.getUserID());
    emp.query();
    while(emp.next()){
        options.push(emp.getUniqueValue());
    }

 I changed this line of code " emp.addQuery('manager',gs.getUserID());". Try to add yourself as manager for two users and test.

I have tried it this way and, unfortunately, it still did not work

I forgot this line, please add it and check

return options;

AshishKM
Kilo Patron

Hi @nathandanek ,

So what is expected when some one doesn't have any direct report. 

 

-Thanks

Ashish


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution