Skip to content

Commit d3a004a

Browse files
Merge pull request #2 from SaiSankar1309/SaiSankar1309-patch-2
Remove all roles from an inactive user
2 parents 4f9a606 + f1abfd9 commit d3a004a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
# Remove all roles from inactive user
3+
4+
Code Snippet : Remove all roles from an inactive user
5+
When a user in an instance is inactive, it's a good practice to remove all roles assigned to that user. Following piece of code helps to remove all the roles from the inactive user.
6+
~~~
7+
var gr = new GlideRecord('sys_user_has_role');
8+
gr.addEncodedQuery('user.active=false');
9+
gr.query();
10+
gr.deleteMultiple();
11+
~~~
12+
This piece of code can be used in scheduled jobs under scheduled script execution tab. This can be run weekly once to check the last one week inactive users and remove them from all assigned roles (if exist).
13+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var gr = new GlideRecord('sys_user_has_role');
2+
gr.addEncodedQuery('user.active=false');
3+
gr.query();
4+
gr.deleteMultiple();

0 commit comments

Comments
 (0)