- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2022 06:24 AM
Hello,
I recently asked this question and got some feedback but unfortunately I still cannot get this to work so I am reaching out again..
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() {
return gs.getUser().isMemberOf('97209ba71bad5d58142dc9192a4bcbff');
},
type: 'validateMember'
});
Here is the Client Script (I have tried request_type multiple different ways (request_type'; I also tied ('request_type')..
function onLoad() {
var ga = new GlideAjax('validateMember');
ga.addParam('sysparm_name', 'validateLoggedUserGroup');
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
if(answer == 'false')//If logged in user IS NOT part of the group
{
for (var i = 0; i < variablesToHide.length; i++) {
g_form.setDisplay(variablesToHide[i], false);
}
}
}
Any idea how to make this work? thanks everyone!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2022 07:31 AM
ok, If the answer variable is giving true when the user is part of the group and vice versa then 90% of the job is done. Lets try few more things, patience pls 🙂
1. Replace
var answer = response.responseXML.documentElement.getAttribute("answer");
with
var answer = response.responseXML.documentElement.getAttribute("answer").toString();
2. Verify the back-end name of the Request Type field (request_type).
3. Try
g_form.setDisplay('request_type', 'false'); //false with quotes

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2022 06:33 AM
Hello Sandy,
The variable variablesToHide is not an array here, so variablesToHide.length and variablesToHide[i] are not going to give the results we need.
Replace your checkGroups function with below code and verify if the core logic works:
function checkGroups(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var variablesToHide = ('request_type'); // Enter your variable backend Name which you want to hide
if(answer == 'false')//If logged in user IS NOT part of the group
{
g_form.setDisplay('request_type', false);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2022 07:06 AM
Hello, thanks so much for your help. I tried this and still no success. Any ideas?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2022 07:13 AM
Some points here:
- Is the field supposed to hide and not hiding?
- Did you alert out the answer variable and check if you are getting true and false based on if the user is part of the group?
function checkGroups(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
if(answer == 'false')//If logged in user IS NOT part of the group
{
g_form.setDisplay('request_type', false);
}
}
3. Try replacing
g_form.setDisplay('request_type', false);
with
g_form.setVisible('request_type', 'false');
4. Is the group (97209ba71bad5d58142dc9192a4bcbff) active? Try giving the name of the group, (silly, but try)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2022 07:25 AM
Hello! thanks for helping. So I updated accordingly, and the alert gives me "false" during testing - so it does show the logged in user is not part of that group.
And you are correct - the request_type field is supposed to be hidden if the user is not part of that group but that is not working. I also confirmed the group is active.
Thanks!