- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 03:10 AM
Hi,
im trying to add to all users with 'itil' role a specific role (template_editor_group) but its not working. what am I doing wrong?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 03:30 AM
Hello @Alon Grod ,
please try with below script
var gr = new GlideRecord('sys_user_has_role');
gr.addEncodedQuery('role=282bf1fac6112285017366cb5f867469');
gr.query();
while(gr.next()){
var role = 'f581eaad0a0a0bc500fbf9055d015838';
var spRole = new GlideRecord('sys_user_has_role');
spRole.initialize();
spRole.user = gr.getValue('user');
spRole.role = role;
spRole.insert();
}
Hope this helps
Mark the answer correct if this helps you
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 03:22 AM
Did you try running the script for limited users?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 03:23 AM
Hi @Alon Grod,
Try below code its working for me
var gr = new GlideRecord('sys_user_has_role');
gr.addEncodedQuery('role!=f581eaad0a0a0bc500fbf9055d015838^ORrole=282bf1fac6112285017366cb5f867469');
//gr.setLimit(5);
gr.query();
while(gr.next()){
var role = 'f581eaad0a0a0bc500fbf9055d015838';
var gr1 = new GlideRecord('sys_user_has_role');
gr1.initialize();
gr1.user = gr.getValue('user');
gr1.role = role;
gr1.insert();
}
If my response helps you to resolve the issue close the question by Accepting solution and hit thumb icon. From Correct answers others will get benefited in future.
Regards,
T Mohan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 03:30 AM
Hello @Alon Grod ,
please try with below script
var gr = new GlideRecord('sys_user_has_role');
gr.addEncodedQuery('role=282bf1fac6112285017366cb5f867469');
gr.query();
while(gr.next()){
var role = 'f581eaad0a0a0bc500fbf9055d015838';
var spRole = new GlideRecord('sys_user_has_role');
spRole.initialize();
spRole.user = gr.getValue('user');
spRole.role = role;
spRole.insert();
}
Hope this helps
Mark the answer correct if this helps you
Thanks