- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2021 09:15 PM
Hi All,
How can I execute below script in background script for one of the user?
gs.getUser().isMemberOf('abc')
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2021 09:30 PM
Like this
Pass the user name or user sys_id
var username = 'abel.tuter';
var isMember = gs.getUser().getUserByID(username).isMemberOf('abc');
gs.info(isMember);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2021 09:24 PM
Hi
first you have to fetch a user record from table sys_user and then you can invoke method isMemberOf():
var grUser = new GlideRecord("sys_user");
grUser.addQuery("user_name", "<USERID>");
grUser.query();
if (grUser.next()) {
if (grUser.isMemberOf("<GROUPNAME>")) {
//your code
}
}
Kind regards
Maik
If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2021 11:03 PM
Thank you, Maik for the response. Marked your answer as helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2021 09:30 PM
Like this
Pass the user name or user sys_id
var username = 'abel.tuter';
var isMember = gs.getUser().getUserByID(username).isMemberOf('abc');
gs.info(isMember);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2021 11:02 PM
Thank you, Ankur for the one-liner script. It helps.