How to get Group record from sys_user_group table with available sys_id
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2019 07:05 AM
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
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2019 07:26 AM
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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2019 07:57 AM
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