How to Assign one specific role to all ITIL users?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 10:49 PM
I want to add one specific role to all ITIL users.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 10:58 PM - edited 12-07-2022 10:58 PM
Create a group which contains all the ITIL users,
then assign the role to group.
It is not suggested to assign roles to users directly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 10:59 PM
Directly assigning a role to a person is not a best practice.
You should create a new group and provide the new role to that group.
After creating a new group, edit group members and add filter - roles is ITIL.
Then add the members into group.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2022 12:10 AM
Try the below code in the background script:
var gr = new GlideRecord("sys_user");
gr.addEncodedQuery('roles=<sys_id of the role ITIL>');
gr.query();
while(gr.next()) {
var role = new GlideRecord('sys_user_has_role')
role.addQuery('user',gr.sys_id);
role.addQuery('role', '<sys_id of the new role ITIL >');
role.query();
if(!role.next())
{
role.initialize();
role.user = gr.sys_id;
role.role = "<sys_id of the new role added>";
role.insert();
}
}
Please hit like and mark my response as correct if that helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2022 01:09 AM