- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2024 01:25 AM
Hi,
I have to remove roles and group when user profile is not active.
Can anyone please help me to achieve that.
Regards,
Nivedita
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2024 01:39 AM
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();
}
}
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2024 01:41 AM - edited 03-07-2024 01:43 AM
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
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.