Query sys_user_group table

DreDay3000
Giga Guru

I would like to query the sys_user_group table to find all groups with certain roles but my script returns undefiled

var grHasRole = new GlideRecord('sys_group_has_role');
grHasRole.addEncodedQuery('roleLIKEportfolio');
grHasRole.query();
while(grHasRole.next()) {
    gs.print(grHasRole.name);
}
1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

Maybe this is closer to what you are trying to do?

var grHasRole = new GlideRecord('sys_group_has_role');
grHasRole.addEncodedQuery('role.nameLIKEportfolio');
grHasRole.query();
while(grHasRole.next()) {
    gs.print(grHasRole.group.name);
}

If you use only the 'role' field, you need to supply a sys_id.  This example returns the group names of all having a role with portfolio in the name. 

View solution in original post

1 REPLY 1

Brad Bowman
Kilo Patron
Kilo Patron

Maybe this is closer to what you are trying to do?

var grHasRole = new GlideRecord('sys_group_has_role');
grHasRole.addEncodedQuery('role.nameLIKEportfolio');
grHasRole.query();
while(grHasRole.next()) {
    gs.print(grHasRole.group.name);
}

If you use only the 'role' field, you need to supply a sys_id.  This example returns the group names of all having a role with portfolio in the name.