How can i get list of all Group managers who have only inactive users under them?

Ankit Kumar6
Tera Contributor
 
1 ACCEPTED SOLUTION

Hi @Ankit Kumar6,

 

Oh! got it your exact need. try this scripts.

 

 

var managerRecords = new GlideRecord("sys_user_grmember");
managerRecords.addQuery("user.active=false^user.managerISNOTEMPTY");
managerRecords.query();
while (managerRecords.next()) {
	gs.info(managerRecords.user.manager.name.toString());
}

 

 

If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers! 👍🏻
Thanks,
Sagar Pagar

The world works with ServiceNow

View solution in original post

9 REPLIES 9

Hi @Community Alums 

I want to get inactive user manager name.

 

Thanks,

Ankit

Not applicable

Anshul21_0-1694156510907.png

But here you want something else.
Thanks,
Anshul

Not applicable

Hi @Ankit Kumar6,

I've tested with the below script which gave the Group manager name for inactive users under the group.

Script:

var arr = [], uniqueGrp = [];
var groupMem = new GlideRecord("sys_user_grmember");
groupMem.addEncodedQuery("user.active=false");
groupMem.query();
while (groupMem.next()) {
    arr.push(groupMem.group.toString());
}
var arrayUtil= new ArrayUtil();  // ServiceNow Out of the Box API.
uniqueGrp.push(arrayUtil.unique(arr));
for (var i = 0; i <uniqueGrp.length; i++) {
    var groupRef = new GlideRecord("sys_user_group");
    groupRef.addQuery("sys_id", uniqueGrp[i]);
    groupRef.addQuery("manager", "!=", "");
    groupRef.query();
    while (groupRef.next()) {
        gs.print("Inactive members group manager is:- " + groupRef.manager.name);
    }
}


Thanks,
Anshul

Hi @Community Alums 

Like in sys_user_group table we have group name field, manager field, and group members.

so my requirement is to get the group name as well as group manager name where all group members are inactive only.

 

Thanks, 

Ankit

Not applicable

Hi @Ankit Kumar6,

In that case, you can use the above script which I have shared. I will give you group manager name and group name as well.

Thanks,
Anshul