- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2024 08:41 AM - edited 11-26-2024 08:13 AM
Hi,
I have a dashboard that I am trying to set the Menu Item visibility of in the Service Portal limited to a few groups of users.
I have condition on the Menu Item set to
gs.getSession().isLoggedIn() && new checkIfGroupMember().verifyMembership();
Here is the script include:
var checkIfGroupMember = Class.create();
checkIfGroupMember.prototype = {
initialize: function() {},
verifyMembership: function() {
if (gs.getUser().isMemberOf() == 'group_sys_id1' || gs.getUser().isMemberOf() == 'group_sys_id2' || gs.getUser().isMemberOf() == 'group_sys_id3')
return true;
}, else: {
return: false,
},
type: 'checkIfGroupMember'
};
This is not working, as any user regardless of group can see the dashboard menu item. Can someone help me where I have gone wrong? I don't know if my script include is incorrect or if my condition is incorrect.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2024 09:30 AM
I was able to get this working on another post by Brad. My syntax was in fact incorrect. The code to achieve this as follows:
var CheckIfGroupMember = Class.create();
CheckIfGroupMember.prototype = {
initialize: function() {},
verifyMembership: function() {
if (gs.getUser().isMemberOf('group_name1') || gs.getUser().isMemberOf('group_name2') || gs.getUser().isMemberOf('group_name3')) {
return true;
} else {
return false;
}
},
type: 'CheckIfGroupMember'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2024 08:50 AM
you were using wrong syntax for isMemberOf
use this
var checkIfGroupMember = Class.create();
checkIfGroupMember.prototype = {
initialize: function() {},
verifyMembership: function() {
if (gs.getUser().isMemberOf('group_sys_id1') || gs.getUser().isMemberOf('group_sys_id2') || gs.getUser().isMemberOf('group_sys_id3'))
return true;
},
else: {
return: false,
},
type: 'checkIfGroupMember'
};
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
11-21-2024 08:56 AM
Hi @Ankur Bawiskar thank you for the suggestion. I have updated my code as you recommended and it is still not working for me. All users still have access to the dashboard. Is it maybe my menu item condition is incorrect?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2024 10:23 AM
@Ankur Bawiskar changing the code still did not work so if you have any other feedback would be great! Thank you Ankur!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2024 09:30 AM
I was able to get this working on another post by Brad. My syntax was in fact incorrect. The code to achieve this as follows:
var CheckIfGroupMember = Class.create();
CheckIfGroupMember.prototype = {
initialize: function() {},
verifyMembership: function() {
if (gs.getUser().isMemberOf('group_name1') || gs.getUser().isMemberOf('group_name2') || gs.getUser().isMemberOf('group_name3')) {
return true;
} else {
return false;
}
},
type: 'CheckIfGroupMember'
};