in script include how to get the list of users for whom the logged in user is manager

Pravallika9
Tera Expert

A is manager of B and B is manager of C.

then C should be able to see the B and A list.

and B should only see the A list.

how to get that list...in script include i want...because i am going to apply it as a dynamic filter to achieve it in report

6 REPLIES 6

Brad Bowman
Kilo Patron
Kilo Patron

I'm confused between your question title and description.  I am C - I have a manager (who has a manager), but I am not anyone's manager.  So if I (C) am the logged in user, I should see all of the users with my manager, and my manager's manager (B & A)?  And if my manager (B) is the logged in user, he should see a list of users with his manager (A)?  And there's only 3 levels here, so A does not have a manager, or at least not that is relevant to this situation?

Yes...One person who is a manager at top will not have any other head manager...My req is if the top manager logged in he should see the second all level of managers and users..... Same way if second level manager logged in he should see only the users for whom he is Manager

That sounds like the opposite of the A, B, C explanation, but see if this fits your requirement

var userArr =[];
var usr = new GlideRecord('sys_user');
usr.addQuery('manager',gs.getUserID());
usr.query();
while(usr.next()){
 userArr.push(usr.getValue('sys_id'));
 var usr2 = new GlideRecord('sys_user');
 usr2.addQuery('manager', usr.sys_id);
 usr2.query();
 while(usr2.next()){
  userArr.push(usr2.getValue('sys_id'));
 }
}
return 'sys_idIN' + userArr;

Vinay Mishra3
Mega Guru

Hi Pravallika,

Please try below code.

var users =[];
		var gr_user = new GlideRecord('sys_user');
		gr_user.addQuery('manager',gs.getUserID());
		gr_user.query();
		while(gr_user.next())
		{

			users.push(gr_user.getValue('sys_id'));
		}
		return 'sys_idIN'+users;

 

Please mark helpful and correct, if it's applicable for you.

Regards,

Vinay