Checking if current user is manager of any group

codedude
Mega Expert

I am trying to check if the current user is a manager of any group. I have checked if the current user is a group member of any group and it works great. I am just not sure of the table and what not to check if the current user is a manager of any group. Can anyone advice?

Group Member Logic:

var uID =   g_user.userID;

var grmember = new GlideRecord('sys_user_grmember');

grmember.addQuery('user', uID);

grmember.addQuery('group.active', true);

grmember.query();

Thanks

1 ACCEPTED SOLUTION

Hi Josh,



Sure. The correction needed in 2nd and 3rd line of code. Please check the script shared and it should work.


Please let me know if you are blocked.


View solution in original post

9 REPLIES 9

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Josh,



You can directly use.


gs.getUser().isMemberOf( ­'Capacity Mgmt'); //Pass the group name here.


This will return true if the memeber is part of the group.


However your script will be


var grmember = new GlideRecord('sys_user_grmember');


grmember.addQuery('user',uID);


grmember.query();


while(grmember.next())


{


//your logic


}


Pradeep,



The group member functionality works fine. I am looking to see if current user is manager of any group, not specific group.


Hi Josh,



Sure. The correction needed in 2nd and 3rd line of code. Please check the script shared and it should work.


Please let me know if you are blocked.


try s.th. like:

var user = gs.getUserID(); //current user sys_id
var target = new GlideRecord('sys_user_group');
target.addQuery('manager', user);
target.query();
if (target.next()) {
answer = true;
} else {
answer = false;
}