get list of groups user belongs to
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-30-2017 11:17 AM
we have created a new custom table with name u_work_group
in which it is having list of 50+ groups, and now we got a requirement that
create a field which refers to sys_user table
and when user is selected then ln a text box to be shown with list of groups that user is member of
agent - type is reference - points to sys_user
groups - type is text box - get group of user
(groups to be separated with comma [,])
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2024 06:18 PM
Hi How did you solve you use case?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-07-2024 09:23 AM
Hi @gtk
You can try the below code it will print all the groups that user belongs to
(function executeRule(current, previous /* previous */) {
var userId ='a8f98bb0eb32010045e1a5115206fe3a'; //change to field name
var userGroups = new GlideRecord('sys_user_grmember');
userGroups.addQuery('user', userId);
userGroups.query();
var groupNames = [];
while (userGroups.next()) {
var groupName = userGroups.group.getDisplayValue();
groupNames.push(groupName);
}
current.groups = groupNames.join(', ');
})(current, previous);
Thanks and Regards
Sai Venkatesh