Can you update a group's type with a fix script?

mattfollowell
Tera Expert

I'm fairly new to Servicenow, been on the platform as an admin for about 4 months, and I am trying to update 32 groups with a fix script vs manually opening the records and updating the group type. Here is what I have:

var grp = new GlideRecord('sys_user_group');
var grname='';
grp.addQuery('sys_id');
grp.query();
    while(grp.next()){
       grname=grp.name;
}
    if(grname.includes("Director")){
        grp.type = grp.type + ",1cb8ab9bff500200158bffffffffff62";
}

I'm missing something, I'm just not sure what.

1 ACCEPTED SOLUTION

Anurag Tripathi
Mega Patron
Mega Patron

Hi Matt,

See my comments below:

var grp = new GlideRecord('sys_user_group');
grp.addQuery('name', 'CONTAINS', 'Director'); // this is the right way to build query
grp.query();
    while(grp.next()){

        grp.type = grp.type + ",1cb8ab9bff500200158bffffffffff62";

grp.update();
}

 

Please test the query by printing the group names before updating the record.

 

-Anurag

 

-Anurag

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Matt,

So you want to update the group which has name containing Director and update the group type.

Do you want to include one more group type to the existing one?

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Anurag Tripathi
Mega Patron
Mega Patron

Hi Matt,

See my comments below:

var grp = new GlideRecord('sys_user_group');
grp.addQuery('name', 'CONTAINS', 'Director'); // this is the right way to build query
grp.query();
    while(grp.next()){

        grp.type = grp.type + ",1cb8ab9bff500200158bffffffffff62";

grp.update();
}

 

Please test the query by printing the group names before updating the record.

 

-Anurag

 

-Anurag