
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2018 09:42 AM
All I am trying to do is see if I am a member of the Managers group (which I am) but this code keeps telling me it's false. Any idea why?
var currentUser = gs.getUser();
if(currentUser.isMemberOf('Managers'))
{
gs.log('true');
}
else
{
gs.log('false');
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2018 12:51 PM
The first thing that comes to mind is that there may be duplicate groups with the same name. Hopefully that is not the case. If there is, perhaps that is why it is returning false. The query finds the first group with that name and unfortunately, you are not a member of **that** group.
See what happens if you remove yourself from a group, then add yourself back in and retry the script. Hopefully it is not an indexing problem, or you are running your script on the instance where you are not part of that group.
Here is a script you can use to get all of your memberships. I modified it so that it will return the names and the sys_id of the group:
var u = gs.getUserID();
var myGroups = getGroupMembership(u);
gs.info(myGroups);
function getGroupMembership(usrID) {
var retArray = [];
var memObj = new GlideRecord('sys_user_grmember');
memObj.addQuery('user', usrID);
memObj.query();
while (memObj.next()) {
var groupInfo = memObj.group.name + '[' + memObj.group + ']';
retArray.push(groupInfo);
}
return retArray;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2018 12:51 PM
The first thing that comes to mind is that there may be duplicate groups with the same name. Hopefully that is not the case. If there is, perhaps that is why it is returning false. The query finds the first group with that name and unfortunately, you are not a member of **that** group.
See what happens if you remove yourself from a group, then add yourself back in and retry the script. Hopefully it is not an indexing problem, or you are running your script on the instance where you are not part of that group.
Here is a script you can use to get all of your memberships. I modified it so that it will return the names and the sys_id of the group:
var u = gs.getUserID();
var myGroups = getGroupMembership(u);
gs.info(myGroups);
function getGroupMembership(usrID) {
var retArray = [];
var memObj = new GlideRecord('sys_user_grmember');
memObj.addQuery('user', usrID);
memObj.query();
while (memObj.next()) {
var groupInfo = memObj.group.name + '[' + memObj.group + ']';
retArray.push(groupInfo);
}
return retArray;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2018 01:41 PM
This is exactly what it was! I removed myself and re-added then it worked! All that time for a glitch!
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2025 12:24 AM
years later, it still occurs. 🙂 Thanks a simple removal and re-addition seemed to fix the issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2018 11:39 AM
Steve, are you trying to use this isMemberOf() function in scoped applications.
If yes, isMemberOf() doesnot work in scoped applications
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2018 11:43 AM
Yeah I wondered the same but as per Steve its returning false ...
So it is working ..aint it