- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2022 07:09 AM
Hello,
Currently I have a requirement to add the ITIL role to all groups of type "Support". There are over 300 groups of this type and if possible I would like to script it to save time. How can I go about configuring this? I tried the solution from this post but nothing happens when I execute the script.
Thanks!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2022 07:53 AM
Try this and replace the group type sys_id with the group type sys_id in your instance and the role sys_id with the sys_id of ITIL role from your instance....
var now_GR = new GlideRecord("sys_user_group");
now_GR.addEncodedQuery("typeLIKE1cb8ab9bff500200158bffffffffff62");
now_GR.query();
while(now_GR.next()) {
var does_not_have_role = new GlideRecord("sys_group_has_role");
does_not_have_role.addQuery('group', now_GR.sys_id);
does_not_have_role.addQuery('role', "282bf1fac6112285017366cb5f867469");
does_not_have_role.query();
if(!does_not_have_role.next()){
var add_new = new GlideRecord("sys_group_has_role");
add_new.initialize();
add_new.group = now_GR.sys_id;
add_new.role = "282bf1fac6112285017366cb5f867469";
add_new.insert();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2022 07:53 AM
Try this and replace the group type sys_id with the group type sys_id in your instance and the role sys_id with the sys_id of ITIL role from your instance....
var now_GR = new GlideRecord("sys_user_group");
now_GR.addEncodedQuery("typeLIKE1cb8ab9bff500200158bffffffffff62");
now_GR.query();
while(now_GR.next()) {
var does_not_have_role = new GlideRecord("sys_group_has_role");
does_not_have_role.addQuery('group', now_GR.sys_id);
does_not_have_role.addQuery('role', "282bf1fac6112285017366cb5f867469");
does_not_have_role.query();
if(!does_not_have_role.next()){
var add_new = new GlideRecord("sys_group_has_role");
add_new.initialize();
add_new.group = now_GR.sys_id;
add_new.role = "282bf1fac6112285017366cb5f867469";
add_new.insert();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2022 08:28 AM
This worked! Thank you so much!