How do we remove a role for a user?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2018 04:18 AM
I am working on a script that can remove a role from the users if they qualify certain conditions. like say, if i wanted to remove role ITIL_user for the users who are inactive.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2018 03:00 AM
I tried the same code again, yet the role is still associated with the user. Thanks for the support though.
var gr = new GlideRecord('sys_user');
gr.addQuery('active',true);
gr.addQuery('first_name','Stacey');
gr.query();
while(gr.next())
{
var role = new GlideRecord('sys_user_has_role');
role.addQuery('role','4af21e54db82130059f5fcdfbf961939'); //sys_id should be given since 'role' is a reference field
role.addQuery('user',gr.sys_id);
role.query();
if(role.next())
{
role.deleteRecord();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2018 03:20 AM
But, it is working for me. Please check the following once.
first_name of Stacey - (Since, string is case sensitive)
active - Re-check if Stacey is active or not
sys_id - Check if you have given correct sysId of the role you wanted to delete
Thanks,
Archana

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2018 09:41 AM
Hi,
Any updates on this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2018 07:59 AM
No, it did not work. However, thanks for your support.