- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2019 10:09 AM
Hi,
I am trying to figure out how to hide a Question Choice on a Select Box type variable on a catalog item form based on whether the logged in user belongs to a specific group.
I created a Business Rule and a Catalog Client Script but it is not working.
I am unsure what I am doing wrong. The goal for this is that when a user views this form, if the logged in user does not belong to this specific group then certain options in the dropdown will not be visible to them.
Any assistance would be greatly appreciated.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2019 01:30 PM
You cannot do it by using display business rule for catalog items. You need to do it by GlideAjax
Here is are scripts for script include and client scripts
Script Include
var AjaxGroupMember = Class.create();
AjaxGroupMember.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isMemeber: function(){
return gs.getUser().isMemberOf('Managers');
},
type: 'AjaxGroupMember'
});
Client script
function onLoad() {
//Type appropriate comment here, and begin script below
var cat = new GlideAjax('AjaxGroupMember');
cat.addParam('sysparm_name','isMemeber');
cat.getXML(isMemofGrp);
function isMemofGrp(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer == 'true'){
g_form.removeOption('st_requestchoice', 'Wholesale');
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2019 10:14 AM
Hello,
Display business rules does not work on catalog item forms. This would be easier if you can tag a role to your group. You need to write an OnLoad client script with following script.
if(g_user.hasRole('your_role')){
g_form.removeOption('choice_var', 'choice_value');
}else{
g_form.addOption('choice_var', 'choice_value', 'choice_lablel');
}
Or else this would require an Ajax call on server side to validate group membership.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2019 10:23 AM
Hi, thank you for replying back.
We cannot add a role to this group due to licenses. How would I go about adding the ajax call to validate the group membership?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2019 10:28 AM
You need a server side function within a script include which checks for the group membership of current user. You can use the same function from your display BR. This will called from your onLoad client script using GlideAjax asynchronously and you can use the same script I added above. You should add an validation on the value returned instead of the roles check.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2019 01:01 PM
I am still quite new to ServiceNow javascript coding. It helps me when I see examples.
Below is my code for my client script. Would this works?
function onLoad() {
//Type appropriate comment here, and begin script below
if(g_scratchpad.grp('Managers'))
{
g_form.removeOption('st_requestchoice', 'Wholesale');
}
else
{
g_form.addOption('st_requestchoice', '');
}
}