How do we remove a role for a user?

sriram9
Giga Contributor

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.

8 REPLIES 8

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();
}
}

 

 

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

Hi,

Any updates on this?

No, it did not work.  However, thanks for your support.