- 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 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 07:41 AM
Thank you!!! this works perfectly! I think another issue was I had that field set to Mandatory - so once I removed that and replaced it with this code it works!
thanks again. you rock.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2022 06:37 AM
Hello Sandy,
Please use below code:
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);
}
}
}
Please mark my respsone as helpful/correct, if it answer your question.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2022 07:07 AM
Hello,
thanks for your help. I tried this and it didn't work. ANything else you can think of?
thanks