If a user having ITIL Or Admin Role Or It-catalog so self service role should be remove

Raj12341
Tera Contributor

Hello Developers, 

I got a requirement that if a user having admin or itil or it-catalog role so self service should be remove.

For this I have written Fix script.

var RUser = new GlideRecord('sys_user_has_role');
 //RUser.addQuery('user', current.user.sys_id);
 RUser.addEncodedQuery('role=4c4b75d11bd1bd50c150a603604bcb13^ORrole=2831a114c611228501d4ea6c309d626d^ORrole=2e697073d010300078f3e6342fe68b34');
 RUser.setLimit(3);
 //gs.log('sys_id of return records' +RUser.sys_id);
 RUser.query();
 //gs.log('sys_id of return records' + RUser.sys_id);
 while (RUser.next()) {
     var Gr = new GlideRecord('sys_user_has_role');
     Gr.addQuery('user', RUser.user);
     Gr.addQuery('role', '2df10056478dd190358e60a2e36d43e6'); //self users role
     Gr.query();
     while (Gr.next()) {
         Gr.deleteRecord();
     }
 }
 
but I am getting problem . It is not updating. Please help me in this
Thanks.
6 REPLIES 6

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Raj12341 

 

You can update the role in Module level

 

LearnNGrowAtul_0-1704284514228.png

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

NOT USEFUL

 

Okay... May I know did yo get any error?

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Can you help me in that script, because in Prod there are 687 users is there , those are having itil and bgm_selfserv.

Now I have to do for all 687 users.

Thanks