- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2025 05:04 AM
Hi Everyone,
I have a requirement that, I need to restrict access to one tab in the portal to specific groups(SIT user & UAT user) only,
But there are no direct group members in both the groups, there are multiple roles(Testing user role & align mgt) in both the groups.
I want to give access the users who are in both the groups (SIT user & UAT user).
Code:
if(gs.getUser().isMemberOf('SIT user') || if(gs.getUser.isMemberOf('UAT User') ){
data.testuser=true
}
result: false even the user is part of the role.
Can you please suggest me.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2025 05:49 AM
why are you giving user direct role?
Instead give role to group and add user to that group?
if those are not added in group then simply use this to check both the roles
gs.hasRole('role A') && gs.hasRole('roleB')
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2025 05:18 AM - edited 04-14-2025 05:18 AM
Hi,
If you are checking to see if user is part of both groups, Not just anyone of them, then you should use AND operation in your if condition instead of OR
if(gs.getUser().isMemberOf('SIT user') && gs.getUser().isMemberOf('UAT User') ){
data.testuser=true
}
Fixed some more syntax issues too
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2025 05:23 AM
Hi Anurag,
Thanks for the quick response.
I tried the same it is returning false.
Actually there no direct group members but, there are some users in roles under that groups.
I want to give access to only the user who are in roles(Testing user role & align mgt) which is under those groups.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2025 05:49 AM
why are you giving user direct role?
Instead give role to group and add user to that group?
if those are not added in group then simply use this to check both the roles
gs.hasRole('role A') && gs.hasRole('roleB')
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2025 06:36 AM - edited 04-14-2025 06:37 AM
I'm not sure I understand what that mean, IF group has a role, and member gets added to that group then users inherit that role.
If users are not directly in that group, then there is no relationship between group and user.
In your case, how is group and user associated?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2025 05:20 AM
The code looks incorrect, no need to for a second if statement, e.g.:
var loggedInUser = gs.getUser();
if(loggedInUser.isMemberOf('SIT user') || loggedInUser.isMemberOf('UAT User')){
data.testuser=true
}