
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2020 09:08 AM
I'd like to pass a sys_user GlideRecord object to "gs.getUser()". Is that possible?
For example, in a script include:
var u = new GlideRecord('sys_user');
u.get('92ece4dfdb3dd41084cc74b5ae9619d7');
if (u) {
if (gs.getUser(u).isMember('Service Desk')) {
/* do something */
}
}
That possible?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2020 09:13 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2020 09:09 AM
This is a great bookmark to have: https://www.servicenowguru.com/scripting/user-object-cheat-sheet/
You can use isMemberOf, here's the example from the post:
if(gs.getUser().isMemberOf(current.assignment_group)){
//Do something...
}
var isMember = gs.getUser().isMemberOf('Hardware');
To do this for a user that isn't the currently logged-in user...
var user = 'admin';
var group = "Hardware";
if (gs.getUser().getUserByID(user).isMemberOf(group)){
gs.log( gr.user_name + " is a member of " + group);
}
else{
gs.log( gr.user_name + " is NOT a member of " + group);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2020 09:10 AM
Yep, I reference that all the time 🙂
Nothing there that I found answered my question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2020 09:12 AM
Ah, looking at your code, you're not getting the current logged in user, you're trying to GlideRecord for a specific user, in this case your GlideRecord query would use the sys_user_grpmember table instead and plug in the addQueries for both the user and group.
var userGr = new GlideRecord("sys_user_grmember");
userGr.addQuery('group.sys_id',grp_sys_id);
userGr.addQuery('user.sys_id',user_sys_id);
userGr.query();
while (userGr.next()) {
//Do something
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2020 09:13 AM
Yeah, that's what I thought.. hehe. I was trying to 'shortcut' it 😛
I figured though that I'd have to go the long way around.
Thanks!