Check if loggedin user is member of group or has an admin role in client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2025 06:24 AM - edited 02-12-2025 06:35 AM
Hello Experts,
I have below script include and catalog client script to check if loggedin user is member of group, but it is not working. Even though user is member of group, it is considering as not a member and alert('3'); is displayed.
Script Include:
Catalog Client script:
In addition to this, I want to override this for admin users as well, how can I achieve that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2025 06:49 AM
Try alerting on answer to see what value it contains, then if it is not what you expect, add logs to the Script Include and/or break up the return to clarify what is happening and add the admin override - whichever value you mean by that:
var checkGroupMember = Class.create();
checkGroupMember.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkGroup: function() {
var answer = '';
var grp = this.getParameter('sysparm_grp');
gs.info('SI grp = ' + grp);
answer = gs.getUser().isMemberOf(grp);
gs.info('SI answer= ' + answer);
if (gs.getUser().hasRole('admin')) {
answer = 'true';
}
return answer;
},
type: 'checkGroupMember'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2025 09:21 AM
@Rocky5 Can you pass group name instead of sys_id in this line ga.addParam('sysparm_grp','k46fc499db8bcc95ed9dff00ba96196b') and check it.