Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

yjaques
Tera Contributor

I just had to create a group which contains all 6000 users in our system. Here's a simple little script that can do just that:

//first create an empty group and get its sys_id

var group_sys_id = '<sys_id here>';

//the users table

var users = new GlideRecord('sys_user');

// Issue the query to the database to get all records

users.query();

while (users.next()) {

        //put some filters here to get rid of any users you don't want to add

        if(users.email.indexOf('unfpa.org') != -1 && users.active && users.source.match(/ldap:uid=.+\, ou=People, o=UNFPA/)) {

              //the group members table

              var members = new GlideRecord('sys_user_grmember')

              members.initialize();

              members.group = group_sys_id;

              members.user = users.sys_id;

              if(members.insert() != null) {

                            gs.log("Updated: "+users.name);

                  } else {

                            gs.log("Failed to update: "+users.name);

                  }

        }

}