- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2024 08:50 AM
I have condition on the Menu Item set to the following:
gs.getSession().isLoggedIn() && new checkIfGroupMember().verifyMembership();
The intent of this condition is to check if the user is Logged In and is part of a specific group.
Here is the client callable script include:
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'
};
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-26-2024 09:53 AM
You might need to pass the current user as an argument in the Script Include. Where exactly are you using this? Is your Script Include in the same scope as whatever is calling it? Your Script Include is not truly Client callable as the extended AjaxProcessor was not added to the beginning, which happens when the box is clicked after the script exists, but it doesn't need to be Client callable in this case - that's only necessary for GlideAjax calls from a client script.
Your if statement is not formatted correctly. Change it to:
if (gs.getUser().isMemberOf('group_name1') || gs.getUser().isMemberOf('group_name2') || gs.getUser().isMemberOf('group_name3')) {
return true;
} else {
return false;
},
You may need to add some log lines to confirm this is running, based on the call in the condition, and confirm the value of gs.getUser(). Do you really need the first part of the Condition - is it possible for users in your environment to not be logged in, yet still be members of groups?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2024 09:50 AM
GlideAjax allows client side code to access the server-side script include. And I do not see how to add a Condition on a dashboard.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2024 10:17 AM - edited 11-26-2024 10:17 AM
@Bert_c1 this is where I am configuring the condition for a dashboard. See below image. I am under the sp_rectangle_menu_item table.
Can you show me an updated script include using GlideAjax to see if that resolves my issue?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2024 09:45 AM
If that works for you, please Accept Solution here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2024 09:53 AM
You might need to pass the current user as an argument in the Script Include. Where exactly are you using this? Is your Script Include in the same scope as whatever is calling it? Your Script Include is not truly Client callable as the extended AjaxProcessor was not added to the beginning, which happens when the box is clicked after the script exists, but it doesn't need to be Client callable in this case - that's only necessary for GlideAjax calls from a client script.
Your if statement is not formatted correctly. Change it to:
if (gs.getUser().isMemberOf('group_name1') || gs.getUser().isMemberOf('group_name2') || gs.getUser().isMemberOf('group_name3')) {
return true;
} else {
return false;
},
You may need to add some log lines to confirm this is running, based on the call in the condition, and confirm the value of gs.getUser(). Do you really need the first part of the Condition - is it possible for users in your environment to not be logged in, yet still be members of groups?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2024 10:06 AM - edited 11-26-2024 10:35 AM
@Brad Bowman thank you for your suggestion. I tried the updated syntax but it still isn't working for me.
You might need to pass the current user as an argument in the Script Include. Can you show me how I would do this in the script?
Where exactly are you using this? I am trying to call this script include via a condition within the Service Portal Menus
Is your Script Include in the same scope as whatever is calling it? Yes, the script include is in the same scope as the service portal menu item. The table is called 'sp_rectangle_menu_item'.
Your Script Include is not truly Client callable as the extended AjaxProcessor was not added to the beginning, which happens when the box is clicked after the script exists, but it doesn't need to be Client callable in this case - that's only necessary for GlideAjax calls from a client script. Can you provide me with an updated script that includes an AjaxProcessor to rule out if that will work?
You may need to add some log lines to confirm this is running, based on the call in the condition, and confirm the value of gs.getUser(). I tried that but I don't think that's possible considering it is a client callable script. The log only documents server-side messages.
Do you really need the first part of the Condition - is it possible for users in your environment to not be logged in, yet still be members of groups? I don't believe so. I think that part of the condition was to make sure the user was not timed out and that a different user was using their machine. In any case, I tried to limit the condition to only display [new checkIfGroupMember().verifyMembership()] and this still didn't work; users outside of those groups can still see the dashboard.