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 05:10 AM
Hello,
I am not saying you to hide the subcategory or remove the dependency what I meant was:-
1) Write a onload client script which will keep the ip address option hidden on load for all users apart from admin
2) write the below code in the onchange client script for field subcategory using this if any user apart from admin selects ip address the subcategory field will be set back to none and it will give an info message to him he cannot select subcategory as ip address.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(!g_user.hasRole('roelname'))
{
if(newValue=='ipaddressvalue')
{
g_form.clearValue('subcategory');
g_form.addInfoMessage('You cannot select ip adress in subcategory')
}
}
}
Please mark answer as correct based on Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2022 05:39 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2022 05:44 AM
The Option will only be hidden on load once you change the category the option will no longer be hidden and that is the reason you also need to implement the 2nd option.
In case of any further doubt let me know.
Please mark answer as correct based on Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2022 05:55 AM
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (!g_user.hasRole('admin')) {
if (newValue == 'network') {
g_form.clearValue('subcategory');
g_form.addInfoMessage('You cannot select ip adress in subcategory');
g_form.removeOption('subcategory','hello','Hello');
}
}
}
I tried this, still the hello appears.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2022 06:01 AM
Hello will always appear when you are using on change I am not sure if you are understanding there is no way to hide that option on change that is why I gave you the on change script that will basically if a user chooses the hello option it will clear the field back to none and give the info message to the user you cannot select hello so it technically restricts user from selecting hello and submitting form.
So a user cans see it but they will not be able to really select it.