Scripts to restrict access to a Tab not working correctly
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 09:44 AM
Hi. Im trying to restrict access to a tab on a form through client script and script include call, as per an article I found here:
I dont think it is working as expected. I added myself to the group, and when I login and open the form, it works as expected. However when I open it as another user, the script returns alert(null) on screen and says youre not a member of the group (they are).
When I impersonate a different user (who is not in the group) - I get the same alerts and message as above
Is that something to do with servicenow not able to run the function properly when impersonating someone? Does the code look correct? Thanks!
Script include
var CheckmemberOf = Class.create();
CheckmemberOf.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
checkGroupMember: function() {
var grp = this.getParameter('sysparm_grp');
return gs.getUser().isMemberOf(grp);
},
type: 'CheckmemberOf'
});
Client script
function onLoad() {
var ga = new GlideAjax('CheckmemberOf');
ga.addParam('sysparm_name', 'checkGroupMember');
ga.addParam('sysparm_grp', '13212312312321'); // dummy sys id
ga.getXML(checkGroup);
}
function checkGroup(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
if (answer == 'true') {
alert('Logged in User is part of group');
} else {
alert('Logged in User is not part of group');
}
}
0 REPLIES 0