Automatic removal of non active users from groups/roles

Sireesha7
Tera Contributor

Hi All,

I need to implement a business rule on insert and update of users, which will check if the Active checkbox is true or false.

If it’s false, it means that the user is inactive and therefore he should be removed from all the groups and all the roles.

 Also, I need to create a warning popup which will show when we try to Save a user profile, when we have made it inactive. This will prevent us from accidentally inactivating a user.

The text should be: Are you sure you want to deactivate this user? Click OK to proceed of Cancel to go back

And then we should have OK and Cancel buttons.

Could any one can please let me know and do the needful.

 

Thanks & Regards,

Sireesha

12 REPLIES 12

@Sireesha7 

Please mark my response as correct and helpful to close the thread if it helped.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Avinash_Patil1
Giga Guru

Hi,

If I am understanding correctly you have two different Requirement.

1. BR on insert /update of user for active true check-- Here you can use on submit client script

2.  Removal of inactive users from all groups.

Is this correct understanding.

 

On Submit client script

function onSubmit() {
    var userActive = g_form.getValue('active');
    if (userActive=='false') {
        return confirm('Are you sure you want to deactivate this user?');
    }
}

 

Use following script in After BR

userInactiveRemoveGroups();
function userInactiveRemoveGroups() {
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user','current.sys_id');
gr.query();
while (gr.next()) {
gr.deleteRecord();

}
}

Mahesh23
Mega Sage

Hi,

I need to create a warning popup which will show when we try to Save a user profile, when we have made it inactive. This will prevent us from accidentally inactivating a user.

 

-- you can use onSubmit() client script suggested by others.


For removing inactive user's role and group membership use Flow Designer

find_real_file.png