Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How to Bulk Update Assignment Groups

Chris17
Tera Contributor

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!

1 ACCEPTED SOLUTION

Linda S
ServiceNow Employee

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();
                 }
       }

View solution in original post

6 REPLIES 6

Linda S
ServiceNow Employee

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();
                 }
       }

Chris17
Tera Contributor

This worked! Thank you so much!