- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2023 06:57 AM
I am trying to hide a subcategory option from all users that are not itil if a specific category is selected. Ie. category "IT Security" is selected then subcategory "Security Exception" is hidden from the list of subcategories. I am able to do this for the category field but when I add a subcategory nothing happens. I was able to verify the values for both the category and subcategory using an alert but when I use "g_form.removeOption('subcategory', 'Security Exception');" It doesn't remove the option.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var cat = g_form.getValue('category');
var subcat = g_form.getValue('subcategory');
if(cat == "IT Security" && (!g_user.hasRole('itil'))) {
//alert(cat);
g_form.removeOption('subcategory', 'Security Exception');
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2023 08:43 AM
Hi @jaubert ,
I Executed almost the same code in my PDI Instance. My client script is an onChange of Category field. It is working perfectly fine.
Points to cross-check:-
1. Impersonate with a non-itil User and check.
2. Cross-check the back end of the Category, Subcategory.
3. Check the onChange client script Field value.
Please find the attached screenshot: and code:-
Code:-
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var cat = g_form.getValue('category');
var subcat = g_form.getValue('sub_category');
if (cat == "IT Security" && (!g_user.hasRole('itil'))) {
alert("entered");
g_form.removeOption('sub_category', 'Security Exception');
//g_form.removeOption('sub_category','Security Exception','Security Exception');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2023 07:19 AM
Hi @jaubert ,
Please double check the backend value of that option, is it 'Security Exception' ,'security_exception' or something else, use the backend value there.
If my answer has helped with your question, please mark it as correct and helpful
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2023 07:29 AM
This is the label and value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2023 08:43 AM
Hi @jaubert ,
I Executed almost the same code in my PDI Instance. My client script is an onChange of Category field. It is working perfectly fine.
Points to cross-check:-
1. Impersonate with a non-itil User and check.
2. Cross-check the back end of the Category, Subcategory.
3. Check the onChange client script Field value.
Please find the attached screenshot: and code:-
Code:-
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var cat = g_form.getValue('category');
var subcat = g_form.getValue('sub_category');
if (cat == "IT Security" && (!g_user.hasRole('itil'))) {
alert("entered");
g_form.removeOption('sub_category', 'Security Exception');
//g_form.removeOption('sub_category','Security Exception','Security Exception');
}
}