How to restrict a choice value in dependent variable based on roles?

Jagadeesvarraj
Tera Contributor

Hi,

 

I have two variables category and subcategory. Subcategory is a dependent to Category variable. How to restrict a particular choice in subcategory which is dependent to category variable based on user role?

 

I have tried using g_form.removeOption as well as g_form.clearOptions, but none of them working for this dependent variable scenario. If I removed the dependency from subcategory, the above methods are working fine. 

 

Can anyone provide a solution on restricting a particular choice in subcategory which is dependent to category variable based on user role.

 

Thanks.

 

12 REPLIES 12

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

Can you show the current configuration that you have it would be easier to assist you.

 

Thanks.

This is the subcategory variable's dictionary. Because of it's dependency to Category variable, I'm facing the issue.

Hello,

 

So the system doesn't grab the dependent subcategories until the category is loaded and each time the category is changed, it goes out to find the dependent subcategories and gets them again, etc.

 

So you cannot achieve what you are trying to however what you can do is:-

 

1) Write a onload client script which will keep the subcategory option hidden on load

 

and then

 

2) Write a on change client script on subcategory with the below code:-(taking email as example). This will clear the field and give a info message if the role user selects the option

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
	if(g_user.hasRole('roelname'))
		{
   if(newValue=='email')
	 {
  g_form.clearValue('subcategory');
 g_form.addInfoMessage('You cannot select email')
	 }

   
}
}

 

Please mark my answer as correct based on Impact.

I should not hide the subcategory field here, that field is important. 

 

for example, selecting network in category, shows me list of values based on network category in the subcategory. In subcategory, i should choose ip address, but this ip address must be visible only the people with the role of admin and not to other roles. all this should work when subcategory is dependent of category.

 

It's because, as per my requirement, subcategory field has more than 300 choices. I can't remove the dependency here, because here, i cant a very very large code here. This is my issue.