Make variable visible only to users in a certain group?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2022 11:58 AM
Hello,
I have a catalog item and I am trying to make a variable (request_type) visible only when the logged in user is part of a specific group (Senior Director Enterprise Group).
I have tried doing this using a script includes as well as an on-load client script. I will post my code for both below. However, this is not working.
Here is the script include (I have client callable selected):
var validateMember = Class.create();
validateMember.prototype = Object.extendsObject(AbstractAjaxProcessor, {
validateLoggedUserGroup: function() {
var arr = [];
var getLoggedInUser = this.getParameter('sysparm_user');
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user',getLoggedInUser);
gr.query();
while(gr.next()){
arr.push(gr.group.getDisplayvalidateMembere().toString());
}
return arr.toString();
},
type: 'validateMember'
});
Here is the On Load client script:
function onLoad() {
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('validateMember');
ga.addParam('sysparm_name', 'validateLoggedUserGroup');
ga.addParam('sysparm_user', g_user.userID);
ga.getXML(checkGroups);
function checkGroups(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var variablesToHide = ['request_type']; // Enter your variable backend Name which you want to hide
var groupsToValidate = 'S97209ba71bad5d58142dc9192a4bcbff';
if (answer.indexOf(groupsToValidate) > -1) { //Check If USer if Member of Group Or Not which you want
for (var i = 0; i < variablesToHide.length; i++) {
g_form.setDisplay(variablesToHide[i], false);
}
}
}
}
I have tried the line where it shows the group sys id using both group sys id and also group name, but neither is working. Any ideas??
Thanks!
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2025 05:52 AM