- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2023 01:17 PM
Hello All,
I am perplexed. I am not able to return a list of groups where the current logged in user is member of the 'parent' field of the sys_user_group table.
Task:
Find all groups where the 'parent' is field is not null.
Find all groups the current logged in user is a member of.
Return a list of groups where the logged in user is member of any 'parent' group.
I am able to return groups if I hard code them in, but not when I use gr.name or gr.sys_id.
Example:
if(gs.getUser().isMemberOf(gr.name)) --- Does not work
if(gs.getUser().isMemberOf('Hard Code Name Here')) Does work
Calling script include in a advanced reference qualifier of a variable on a catalog item.
javascript:new global.getGroups().GetUserGroups();
Script Include:
var getGroups = Class.create();
getGroups.prototype = {
initialize: function() {
},
GetUserGroups : function()
{
var usersGroupList = [];
var gr = new GlideRecord('sys_user_group');
gr.addNotNullQuery('parent');
gr.query();
while(gr.next())
{
if(gs.getUser().isMemberOf(gr.name))
{
usersGroupList.push(gr.getUniqueValue());
}
gs.log('-------------' + usersGroupList + '====' + gs.getUserDisplayName());
}
return 'sys_idIN' + usersGroupList;
},
type: 'getGroups'
};
Thank you in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2023 02:00 PM
Yeah, I am an idiot. Figured it out.
I was returning the wrong group in my initial glide record query.
These two lines fixed my issue.
var groupName = gr.parent.name;
if(gs.getUser().isMemberOf(groupName))
var getGroups = Class.create();
getGroups.prototype = {
initialize: function() {
},
GetUserGroups : function(user)
{
var usersGroupList = [];
var gr = new GlideRecord('sys_user_group');
gr.addNotNullQuery('parent');
gr.query();
while(gr.next())
{
var groupName = gr.parent.name;
if(gs.getUser().isMemberOf(groupName))
{
usersGroupList.push(gr.getUniqueValue());
}
gs.log('-------------' + groupName + '====' + gs.getUserDisplayName());
}
return 'sys_idIN' + usersGroupList;
},
type: 'getGroups'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2023 02:00 PM
Yeah, I am an idiot. Figured it out.
I was returning the wrong group in my initial glide record query.
These two lines fixed my issue.
var groupName = gr.parent.name;
if(gs.getUser().isMemberOf(groupName))
var getGroups = Class.create();
getGroups.prototype = {
initialize: function() {
},
GetUserGroups : function(user)
{
var usersGroupList = [];
var gr = new GlideRecord('sys_user_group');
gr.addNotNullQuery('parent');
gr.query();
while(gr.next())
{
var groupName = gr.parent.name;
if(gs.getUser().isMemberOf(groupName))
{
usersGroupList.push(gr.getUniqueValue());
}
gs.log('-------------' + groupName + '====' + gs.getUserDisplayName());
}
return 'sys_idIN' + usersGroupList;
},
type: 'getGroups'
};