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

pihu2
Kilo Explorer

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!

2 REPLIES 2

Murthy Ch
Giga Sage

Hi @pihu 

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

Thanks,
Murthy

Anshu_Anand_
Kilo Sage
Kilo Sage

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.

find_real_file.png

find_real_file.png

It will add all the members having ITIL role

If its helpful, mark answer as correct

Regards,
Anshu