How to get Group record from sys_user_group table with available sys_id

madamski
Kilo Contributor

I have a group Sys Id available to me in my code but not the group object, which I need.

 

How do I build out a query to get that group's object, from the sys_user_group table if I have that sys_id? I tried the following but it didn't work

var group_rec;

    var glide = new GlideRecord('sys_user_group');
        glide.addQuery('group', record.assignment_group);
        glide.query();

    while (glide.next()) {
      group_rec = glide.group
    }

// group_rec = NULL
6 REPLIES 6

Inactive_Us1474
Giga Guru

Use any of the below two ways. 

var id = ""; // sys_id of the group

var gr = new GlideRecord('sys_user_group');

gr.addQuery('sys_id',id);

gr.query();

if(gr.next()) {

gs.info('Group Object - '+gr);

}

-------

var id = ""; //sys_id of the group

var gr = new GlideRecord('sys_user_group');

gr.get(id);

gs.info('Group Object' +gr);

DirkRedeker
Mega Sage

Hi

Your script looks good. So, the reason, why it does not work is, that

a) "record" does not contain a valid GlideRecord

b) "record" does not have the field "assignment_group"

c) the value of the field "assignment_group!" does not have a Relation to the "group" table, but maybe has only a String

 

Can you confirm, that the above three points are correct?

Let me know, if that solved your issue, and mark my answer as correct and helpful,please.

 

BR

Dirk