
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2024 03:34 PM - edited 11-10-2024 04:41 PM
So I have used some other posts to achieve most of what I need to do, but have run into an issue that I need further assistance with please.
I have a script include and a catalog client script that work together to hide variable values from everyone who is not a member of a specific group - that works fine as long as the variables are set to be hidden on the RITM and sc_task.
The issue that I have is that some of the fields need to only be made visible on the catalog item if the answer to previous variables are certain values, therefore I have catalog ui policies to show or hide under which is cancelling out the hiding values on the variables to all but the group scripted to see it.
So ultimately does someone know how I can still hide the variable values from all but to a particular group without losing the ability to show or hide questions at the catalog item level depending on answers selected?
Here are the scripts I'm using currently:
Catalog Client Script:
OnLoad
UI Type = All
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 = ['variable1', 'variable12', 'variable3', 'variable4', 'variable5'];
var groupsToValidate = 'group_name';
if (answer.indexOf(groupsToValidate) > -1) { // Check if user is a member of the group
for (var i = 0; i < variablesToHide.length; i++) {
g_form.setDisplay(variablesToHide[i], true);
}
}
}
}
Script Include:
Name: validateMember
Client callable = true
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.getDisplayValue().toString());
}
return arr.toString();
},
type: 'validateMember'
});
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2024 08:05 PM - edited 11-10-2024 08:05 PM
Ok, so I actually managed to find a solution myself (as in I found the post the solution was in, not that I came up with it on my own).
Credit needs to @AnirudhKumar for the solution they posted in this thread:
Solved: Re: Variable visible only to people in certain gro... - Page 2 - ServiceNow Community
I have to change the script include and the catalog client script, they are similar but have a couple of key differences, but here is what worked for me.
Script include: (make sure it is client callable)
Name: validateMember
var validateMember = Class.create();
validateMember.prototype = Object.extendsObject(AbstractAjaxProcessor, {
validateLoggedUserGroup: function() {
return gs.getUser().isMemberOf('87ab8760a5f55e10b68ea73051eb7ed4'); //Conflict of Interest group sys_id
},
type: 'validateMember'
});
Catalog Client Script
Type - OnLoad
UI Type - All
function onLoad() {
var ga = new GlideAjax('validateMember'); //name of the script include
ga.addParam('sysparm_name', 'validateLoggedUserGroup');
ga.getXML(checkGroups);
}
function checkGroups(response) {
var answer = response.responseXML.documentElement.getAttribute("answer").toString();
var variablesToHide = ('variable1', 'variable2', 'variable3', 'variable4', 'variable5'); // 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('variable1', 'false');
g_form.setDisplay('variable2', 'false');
g_form.setDisplay('variable3', 'false');
g_form.setDisplay('variable4', 'false');
g_form.setDisplay('variable5', 'false');
}
}
}
This has resulted in the fields I want hidden on the catalog item are still hidden unless the answer given makes another variable visible at that level, but still hides them at the RITM and sc_task level if the logged in user is not a member of the allocated group.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2024 04:35 PM
@Moedeb Any reason you are using write roles in variables ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2024 04:43 PM
@Gangadhar Ravi sorry not sure what you mean? I'm not using write roles to my knowledge - I'm just hiding variable values from most users.
There is information that within the catalog item requests that need to be seen by all and some that need to be hidden, so would rather not so it via acl's if possible

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2024 08:05 PM - edited 11-10-2024 08:05 PM
Ok, so I actually managed to find a solution myself (as in I found the post the solution was in, not that I came up with it on my own).
Credit needs to @AnirudhKumar for the solution they posted in this thread:
Solved: Re: Variable visible only to people in certain gro... - Page 2 - ServiceNow Community
I have to change the script include and the catalog client script, they are similar but have a couple of key differences, but here is what worked for me.
Script include: (make sure it is client callable)
Name: validateMember
var validateMember = Class.create();
validateMember.prototype = Object.extendsObject(AbstractAjaxProcessor, {
validateLoggedUserGroup: function() {
return gs.getUser().isMemberOf('87ab8760a5f55e10b68ea73051eb7ed4'); //Conflict of Interest group sys_id
},
type: 'validateMember'
});
Catalog Client Script
Type - OnLoad
UI Type - All
function onLoad() {
var ga = new GlideAjax('validateMember'); //name of the script include
ga.addParam('sysparm_name', 'validateLoggedUserGroup');
ga.getXML(checkGroups);
}
function checkGroups(response) {
var answer = response.responseXML.documentElement.getAttribute("answer").toString();
var variablesToHide = ('variable1', 'variable2', 'variable3', 'variable4', 'variable5'); // 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('variable1', 'false');
g_form.setDisplay('variable2', 'false');
g_form.setDisplay('variable3', 'false');
g_form.setDisplay('variable4', 'false');
g_form.setDisplay('variable5', 'false');
}
}
}
This has resulted in the fields I want hidden on the catalog item are still hidden unless the answer given makes another variable visible at that level, but still hides them at the RITM and sc_task level if the logged in user is not a member of the allocated group.