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

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Aparna Gurav 

 

This approach breaks security protocols. Even though we’re in the IT industry, we should never allow a manager to request delegation on behalf of a direct report — this is more of an exception than a rule. We should educate users that if someone is going on leave, they must set up their own delegation. Instead of shifting the burden to the manager, we could define some KRAs around this. Imagine a manager with 20 direct reports — if 5 of them are on leave, that creates a significant overhead. Now consider if this happens weekly or monthly — the impact adds up quickly.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

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

@Ankur Bawiskar : Thank you for the response. I applied the same logic and impersonated the line manager, but now he can see the entire list of users.

@Aparna Gurav 

share your script.

It worked fine for me

AnkurBawiskar_1-1759150140007.png

 

-> I am manager of 4 users

-> So I will get those 4 users

-> Then each of those reportees are again manager of some other users

-> Abel is manager of 2 users, Annabelle is manager of 2 users, Isabell is manager of 1 user, Mabel is manager of 2 users

-> Total 4+2+2+1+2 => 11 Users

Below Output = 11 Users

AnkurBawiskar_0-1759150052567.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