Auto remove inactive managers from active groups and inactive users from active groups

Sai Santhosh Ch
Tera Contributor

When a user goes inactive we need to check if that user was a manager of a group or if that user was a member of   a group. If the user is a member of a group we will remove them from that group. If they were a manager of that group we need to replace that user with their manager and notify the manager that they have been assigned the group manager.

1 ACCEPTED SOLUTION

Mike Allen
Mega Sage

A business rule on sys_user that says:



before Insert


condition current.active.changesTo('false')



var group = new GlideRecord('sys_user_group');


group.addQuery('manager', current.sys_id);


group.query();


while(group.next()){



group.manager = current.manager;


group.update();


gs.eventQueue('group.manager.changed', group, group.manager, current.name);



}



var grmember = new GlideRecord('sys_user_grmember');


grmember.addQuery('user', current.sys_id);


grmember.query();


while(grmember.next()){



grmember.deleteRecord();



}


View solution in original post

10 REPLIES 10

Hi Mike,



I have a question which is similar to this type. Please go through the below mail thread.


https://community.servicenow.com/thread/212956




Thanks


Shrikanth


jo_2016
Tera Contributor

Hi, 

 

Running into similar issue however is there a way to validate the user was inactive for 30 days prior to the business rule run? 

Reason being if someone gets locked out with synced accounts this will make the user appear inactive in servicenow however they are just having a PW reset issue. 

nagam
Kilo Contributor

Hi Jo, You may also want to consider last login time or updated time stamp in sys_user table if you are getting your daily feed from ADS.

Sara3
Giga Guru

Hi. We have a similar requirement, but we want to wait 24 hours after they have been inactivated before removing them from the group.  What is the best way to do that?  I like the idea of the business rule, but can it run based on that 24 hours requirement?  Other suggestions have been to use a scheduled job or workflow.  Thanks!

I would have a scheduled job that runs every night, finds all the inactive users that have been inactive for greater than 24 hours, then run the job to do what you need.