- 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:32 PM
Hi
the "gs.getUser()" function is intended to act on the CURRENT user. That is the user logged in and calling this function. see:
If you want to check the membership with "isMemberOf()" of any particular user for a given group, you should use the option, that Ankur proposed.
If you want to know, where you can find the assignments of users to Groups, you can have a look to the database table [sys_user_grmember], which you can show by typing "sys_user_grmember.list" to your Application Navigator in the Classic UI and pressing <ENTER>.
Effectively, the "isMemberOf()" API ready that table data.
Note, that the "gs.getUser().getUserByID(username)" function call does not work in Scoped Apps, it only works in Global Scope.
Let me know if that answers your question and mark my answer as correct and helpful.
BR
Dirk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2021 11:03 PM
Thank you Dirk, for the response. Marked your answer as helpful.