The CreatorCon Call for Content is officially open! Get started here.

group member inactive

keerthi35
Tera Contributor
Group manager should be notified when any group member becomes inactive
10 REPLIES 10

Hi @keerthi35 

Hope you are using after BR on the sys_user table and keeping the condition as active changes to false

Change your code:

 

var gr = new GlideRecord('sys_user_grmember');
gr.addQuery("user", current.getUniqueValue());
gr.query();
var grpManagers = [];
while(gr.next()){
       if(grpManagers.indexOf(gr.group.manager.toString()) >-1){
               grpManagers.push(gr.group.manager.toString());
        }
}
gs.eventQueue("member.left",gr,grpManagers.toString(),"");


 

 

 

Best Regards
Aman Kumar

piyushsain
Tera Guru

Create a after BR on table sys_user table that should be triggered when user becomes inactive

var userGroup = new GlideRecord('sys_user_grmember');
userGroup .addQuery('user',current.getDisplayValue('sys_id');
userGroup .query();
while(userGroup .next()){
gs.eventQueue('eventname','userGroup'); //trigger an event which sends a Notification to the users manager
}

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain

hi @piyushsain 

 

what is event name? how can create?

System Policy -> Events -> Registry

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain

Amit Gujarathi
Giga Sage
Giga Sage

HI @keerthi35 ,
I trust you are doin great.

  • Create a new Business Rule that triggers on updates to the User (sys_user) table.
  • Set the condition to check if the user's active field has been changed to false (inactive).
  • In the script, identify the groups to which the user belongs and find the managers of those groups.
  • (function executeRule(current, previous /*null when async*/) {
        // Check if the user has been set to inactive
        if (current.active == false && previous.active == true) {
            // Query to find groups where the user is a member
            var grMember = new GlideRecord('sys_user_grmember');
            grMember.addQuery('user', current.sys_id);
            grMember.query();
            
            while (grMember.next()) {
                // Find the manager of the group
                var grGroup = new GlideRecord('sys_user_group');
                if (grGroup.get(grMember.group)) {
                    var managerSysId = grGroup.manager;
                    
                    // Send notification to the manager
                    gs.eventQueue("your_custom_event", current, current.user_name, managerSysId);
                }
            }
        }
    })(current, previous);
    

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi