I need to add a new role to all user having ITIL role, there are more than 100 users with itil role, adding this role each one can be a very long process. Is it possible to achieve this with background scripts? If yes please suggest the script for th
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2022 10:21 PM
Hi All,
I need to add a new role to all user having ITIL role, there are more than 100 users with itil role, adding this role each one can be a very long process. Is it possible to achieve this with background scripts? If yes please suggest the script for the same. Need to add role only to itil users.
Thanks in Advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2022 10:27 PM
Hi
Try something like below in background scripts or fix scripts:
try
{
var grU=new GlideRecord("sys_user_has_role");
grU.addEncodedQuery("role.name=itil"); //taking the users who's having itil role
grU.query();
while(grU.next())
{
var grX=new GlideRecord("sys_user_has_role");
grX.initialize();
grX.role="your new role sys_id"; //give new role sys_id
grX.user=grU.getValue("user");
grX.insert();
}
}
catch(e)
{
gs.info("Error is:"+e.message);
}
Hope it helps
Thanks,
Murthy
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2022 10:29 PM
Dont need to write any scripts. an easy method
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.
1. After creating a new group, edit group members and add filter - roles is ITIL.
Then add the members.
It will add all the members having ITIL role
If its helpful, mark answer as correct
Anshu