How to remove role for user in background script

Surya67
Tera Contributor

Hi,

 

I have two roles snc_internal and snc_external. 

 

Ex:

user - Test(Internal user)

Test user has snc_internal and snc_external roles.

Now I want to remove snc_external role for Internal users(Test user).

 

I have around 1000 users with same case.

How can I remove snc_external for Internal user

 

2 REPLIES 2

Anil Lande
Kilo Patron

Hi,

You can write a fix script and glide to sys_use_has_role table.

Get records role = snc_external and delete records.

Please check below link for script:

https://community.servicenow.com/community?id=community_question&sys_id=9c39364edb0d4c181cd8a345ca96...

 

Thanks,

Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

AnirudhKumar
Mega Sage
Mega Sage
var userRole = new GlideRecord('sys_user_has_role');
userRole.addEncodedQuery('role.name=snc_internal^ORrole.name=snc_external');
userRole.query();

userRole.deleteMultiple();

Execute the script in background script

 

Warning : Whoever has snc internal or external roles, they will lose them. This will happen to all users. Add another query to ensure snc internal and external is not removed to key users