i know the group name using get() method how we can get single group in group table

mani55
Tera Contributor

i know the group name using get() method how we can get that single group in group table

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@mani55 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

6 REPLIES 6

@mani55 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Badrinarayan
Tera Guru

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