- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-26-2025 03:00 AM
i know the group name using get() method how we can get that single group in group table
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-26-2025 03:12 AM
simply use this
var groupName = 'Your Group Name'; // Replace with your group name
var groupGR = new GlideRecord('sys_user_group');
if (groupGR.get('name', groupName)) {
// Group found
gs.info('Group found: ' + groupGR.name);
} else {
// Group not found
gs.info('Group not found');
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-26-2025 03:41 AM
yes but better to use IF along with get in case record is not found then it causes an issue
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-26-2025 03:12 AM
Hi @mani55 ,
To retrieve a single group from the sys_user_group table in ServiceNow using the get() method, you can do something like this in a script:
var groupName = 'Example Group Name'; // Replace with the actual group name
var group = new GlideRecord('sys_user_group');
group.addQuery('name', groupName); // Query the group by name
group.query();
if (group.next()) {
// Access group properties
gs.info('Group found: ' + group.name);
} else {
gs.info('Group not found');
}
Replace the Group name with the name of the group you want to retrieve.
If you want to give it with sysid, then try the below code
var groupSysId = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; // Replace with actual Sys_ID
var group = new GlideRecord('sys_user_group');
if (group.get(groupSysId)) {
// Access group properties
gs.info('Group found: ' + group.name);
} else {
gs.info('Group not found');
}
Replace groupSysId with the actual Sys_ID of the group you want to fetch.
If this solution resolves your query, please accept the solution and mark it as helpful.
Thanks & regards,
Badrinarayan