I want to assign a single role to more than 1000 users at a single time. How can I do that?

SK36
Tera Contributor

I have to assign a "single same role"(e.g : itil) to 1000 users in a single time. How can I do that. any help would be appreciated.

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi @siva shankar ,

Adding users > groups > roles is best practice. Adding roles directly to users is bad practice in ServiceNow.

add users to group and then assign the role to group. now you just need to add users to that group , this way all those users will have role.

Mark my answer correct & Helpful, if Applicable.

Thanks,

Sandeep

View solution in original post

3 REPLIES 3

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Is this a one time thing or should you do this more often?

My first through would be writing a small Fix Script. 

Question:

Why mentioning adding a role? Adding roles directly, is bad practice. Consider adding those users to a group instead.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020-2022 ServiceNow Community MVP
2020-2022 ServiceNow Developer MVP

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Community Alums
Not applicable

Hi @siva shankar ,

Adding users > groups > roles is best practice. Adding roles directly to users is bad practice in ServiceNow.

add users to group and then assign the role to group. now you just need to add users to that group , this way all those users will have role.

Mark my answer correct & Helpful, if Applicable.

Thanks,

Sandeep

Sagar Pagar
Tera Patron

Hi,

 

I would suggest you to create a group, add users to that group and assign the role to group.

 

Here is the script to add multiple users to group.

var group_sys_id = '<group_sys_id>'; // your group sysid

var users = new GlideRecord('sys_user');
users.addActiveQuery(); // brings all active records
users.addEncoddedQuery("add-your-query-here");
users.query();
while (users.next()) {

    var members = new GlideRecord('sys_user_grmember');
    members.addEncodedQuery('group=' + group_sys_id + '^user=' + users.sys_id);
    members.query();
    if (members.getRowCount() == 0) {
        members.initialize();
        members.group = group_sys_id;
        members.user = users.sys_id;
        members.insert();
    }
}

 

Thanks!

Sagar Pagar

The world works with ServiceNow