Deleting inactive users

I_Das
Tera Contributor

Hello all,

 

I want to remove inactive users from assignment group, I want to write a business rule on group member table.

 

When: before

 

Script:

(function executeRule(current, previous /*null when async*/) {
if (current.user) {
    var userGr = new GlideRecord('sys_user');
    if (userGr.get(current.user)) {
if (!userGr.active) {
            current.deleteRecord(); // Remove the user from the group
        }
 }
}
})(current, previous);
 
But it is not deleting the existing inactive users from the group. If you could tell me the issue in this it will be very helpful.
 
Thanks & Regards,
I Das
12 REPLIES 12

I_Das
Tera Contributor

Hello @dhanrajb ,

 

Thank you for the reply. I had done it with background script It worked. I just wanted to know if BR will be possible with existing user. I got that it's not possible.

 

Thanks & Regards,

I Das

Sai Krishna6147
Mega Guru

Hello @I_Das  ,

please check with this background script:

 

var groupMembers = new GlideRecord('sys_user_grmember'); // Group Members table
groupMembers.query();
while (groupMembers.next()) {
var user = new GlideRecord('sys_user');
if (user.get(groupMembers.user) && !user.active) {
groupMembers.deleteRecord(); // Remove inactive user from the group
}
}

 

 

If you still want to use the business rule, you’ll need to ensure that it gets triggered for the existing inactive users. One way to do this is to trigger an update on the "sys_user_grmember" records to re-evaluate them, but this would only work on records that are being updated.

You can combine the business rule with a scheduled job for proactive cleanup and batch processing for older records.

 

Thanks & Regards,
SK6147

Hello @Sai Krishna6147 

 

Thank you for the reply. I had done it with background script It worked. I just wanted to know if BR will be possible with existing user. I got that it's not possible.

 

Thanks & Regards,

I Das