How to allow line managers to request delegates for the direct reports of their direct reports

Aparna Gurav
Tera Contributor

Hello All,

Could someone assist with the following requirement?

I’m working with the Request Delegate catalog item. The goal is to allow line managers to request delegates for the direct reports of their direct reports (i.e., two levels down in the org chart).

 

If a manager impersonates and opens this catalog item, they should only see their direct reportees and second-level reportees (i.e., the reportees of their reportees) in the "Requested For" variable on the portal.

Can anyone suggest how to implement this functionality?


AparnaGurav_0-1759147091839.png

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Aparna Gurav 

you can use advanced ref qualifier with this

something like this

javascript: var query = '';
var userId = gs.getUserID();
var users = [];

// Direct reports
var gr = new GlideRecord('sys_user');
gr.addQuery('manager', userId);
gr.query();
while (gr.next()) {
    users.push(gr.getUniqueValue());
}

// Second-level reports
if (users.length > 0) {
    var gr2 = new GlideRecord('sys_user');
    gr2.addQuery('manager', 'IN', users.join(','));
    gr2.query();
    while (gr2.next()) {
        users.push(gr2.getUniqueValue());
    }
}

query = 'sys_idIN' + users.toString(); // list of user sys_ids
query;

AnkurBawiskar_0-1759148644670.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

5 REPLIES 5

@Ankur Bawiskar : It's working now, it was a typo in my script.