How to get members of selected business unit group ?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2025 09:26 PM
Script include:
var GetUsersFromBusinessUnit = Class.create();
GetUsersFromBusinessUnit.prototype = {
initialize: function() {},
getUsers: function(businessUnitID) {
var userList = [];
var buGR = new GlideRecord('business_unit');
if (buGR.get(businessUnitID)) {
var groupID = buGR.getValue('u_group');
if (groupID) {
var groupMemberGR = new GlideRecord('sys_user_grmember');
groupMemberGR.addQuery('group', groupID);
groupMemberGR.query();
while (groupMemberGR.next()) {
userList.push(groupMemberGR.getValue('user'));
}
}
}
return userList.join(',');
},
type: 'GetUsersFromBusinessUnit'
};
Reference Qualifier: javascript:GetUsersFromBusinessUnit.getUsers(current.variables.business_unit)
I am still on getting correct results.... Let me know if I am missing something.
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2025 10:02 PM
Hi @Annie Scott
your script looks correct, you might want to temporarily log the businessUnitID and groupID variables to ensure that the correct values are being passed to the query.
I hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.
thank you
Rajesh
Community Alums
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2025 10:10 PM
Hi @Annie Scott ,
Can you verify with error handling:
for example:
- you can add if (!businessUnitID) { gs.error('Business Unit ID is not provided'); return ''; } code bellow var userList = [];
- if (!groupID) { gs.error('No group found for business unit: ' + businessUnitID); return ''; } code after var groupID = buGR.getValue('u_group');
- if (!groupMemberGR.hasNext()) { gs.error('No users found for group: ' + groupID); } code after groupMemberGR.query();
- Lastly, add gs.error('No business unit found with ID: ' + businessUnitID); return '' in else after while loop.