Hide Question Choice based on logged in user belonging to group

Dazler
Mega Sage

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.

find_real_file.png

 

find_real_file.png

 

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.

find_real_file.png

 

Any assistance would be greatly appreciated.

1 ACCEPTED SOLUTION

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

find_real_file.png

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');
			
		}
	}
}

View solution in original post

6 REPLIES 6

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

find_real_file.png

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');
			
		}
	}
}

This worked perfectly.  Thank you!