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:11 AM
Hi,
so you have the sys_id of the record and you need glide record object for that
sample script here: gr is that object; you can use that to get value from that group record such as name of group, manager, group email etc
var gr = new GlideRecord('sys_user_group');
gr.addQuery('sys_id', 'sysId'); // give the sys_id here
gr.query();
if(gr.next()){
gs.info('gr is the object');
}
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2022 02:03 AM
How to compare manager of requested_by with assignment group manager .need to check if both the managers are same or not.Thanks you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2019 07:15 AM
Hi,
You can try this out.
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;
var group = new GlideRecord('sys_user_group');
if(group.get(group_rec)){
//group object can be accessed here by dotwalkin on group variable
gs.info("Name: "+group.name);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2019 07:22 AM
Simply Query the sys_user_group table as below, if all you wanted was a Group Object by a sys_id of the Group.
var groupGr = new GlideRecord('sys_user_group');
groupGr.get(record.assignment_group);
ig(groupGr){
var group_rec = groupGr;
}