I have to remove roles and group when user profile is not active.

niveditakumari
Mega Sage

Hi, 

 

I have to remove roles and group when user profile is not active. 

Can anyone please help me to achieve that. 

 

Regards, 

Nivedita 

 

 

1 ACCEPTED SOLUTION

Harish KM
Kilo Patron
Kilo Patron

Hi @niveditakumari roles are always tied to group. There are 2 ways to do this

1. using flow designer , no code required, trigger will be when active is false

 

2. using after update BR,

Cond: active is false

script:

var user = new GlideRecord('sys_user');
user.addQuery('active', false);
user.query();
while (user.next()) {
// Remove groups
var grp = new GlideRecord('sys_user_grmember');
grp.addQuery('user.sys_id', user.sys_id);
grp.query();
while (grp.next()) {
grp.deleteMultiple();
}
}

Regards
Harish

View solution in original post

5 REPLIES 5

SN_Learn
Kilo Patron
Kilo Patron

Hi @niveditakumari ,

 

Please go through the below articles:

 

Remove a user who is inactive from all roles and groups 

 

https://conyxit.com/servicenow-script-to-remove-inactive-user-from-all-the-groups-and-roles/ 

 

Removing Roles of Inactive users 

 

https://www.servicenow.com/community/developer-forum/how-to-remove-roles-and-groups-for-inactive-use... 

 

 

Please le me know your views and Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.