How to write a script in ServiceNow to get all the Active groups with Inactive members

Bhagya
Tera Contributor

How to write a script in ServiceNow to get all the Active groups with Inactive members.

1 ACCEPTED SOLUTION

Sulabh Garg
Mega Sage
Mega Sage

Hello Bhagya,

You can use below script to find the active groups with Inactive users information.

 

var grSUG = new GlideRecord('sys_user_grmember');
grSUG.addEncodedQuery("group.active=true^user.active=false");  //Filter condition
grSUG.query();
while (grSUG.next()) {
gs.info('group: ' + grSUG.getValue('group'));
gs.info('user: ' + grSUG.getValue('user'));
}

 

Please Mark Correct/helpful, if applicable, Thanks!! 

Regards

Sulabh Garg

Please Mark Correct/helpful, if applicable, Thanks!!
Regards
Sulabh Garg

View solution in original post

3 REPLIES 3

Sulabh Garg
Mega Sage
Mega Sage

Hello Bhagya,

You can use below script to find the active groups with Inactive users information.

 

var grSUG = new GlideRecord('sys_user_grmember');
grSUG.addEncodedQuery("group.active=true^user.active=false");  //Filter condition
grSUG.query();
while (grSUG.next()) {
gs.info('group: ' + grSUG.getValue('group'));
gs.info('user: ' + grSUG.getValue('user'));
}

 

Please Mark Correct/helpful, if applicable, Thanks!! 

Regards

Sulabh Garg

Please Mark Correct/helpful, if applicable, Thanks!!
Regards
Sulabh Garg

In this same script if I want only group names which starts with G_IT then how can i get that.

Hi,

Try below code

var grSUG = new GlideRecord('sys_user_grmember');
grSUG.addEncodedQuery("group.active=true^user.active=false^groupSTARTSWITHG_IT");  //Filter condition
grSUG.query();
while (grSUG.next()) {
gs.info('group: '+grSUG.getDisplayValue('group'));
gs.info('group: ' + grSUG.getValue('group'));
gs.info('user: ' + grSUG.getValue('user'));
}

 

Please mark my response as correct or helpful if applicable