How to restrict a choice value in dependent variable based on roles?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2022 01:46 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2022 03:36 AM
Hello,
Can you show the current configuration that you have it would be easier to assist you.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2022 03:43 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2022 04:42 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2022 05:04 AM
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.