How to hide the values of subcategories
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2024 12:54 AM
Hello Everyone,
We have a field called 'category' on the incident form, and based on the selected category, the subcategory field values are displayed. We have options A, B, C, and D for the category field, and options 1, 2, 3, 4, and 5 for the subcategory field. However, we want to hide the subcategory option '4' when 'B' is selected in the category field. How can we achieve this?
Note: We only want to hide this option on the form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2024 10:11 PM
If it is to remove an option, you can go for onChange client script
var category = g_form.getValue('category');
if (category == "B") {
g_form.removeOption('sub_category', '4');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2024 10:21 PM
Hi @SmithO
Create a new Client Script ,
- Name: Adjust Subcategory Options
- Table: Incident
- Type: onChange
- Field: Category
var categoryValue = g_form.getValue('category');
if (categoryValue == 'B') {
// If category is ‘B’, hide subcategory option ‘4’
g_form.removeFieldOption('subcategory', '4');
Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2024 10:23 PM
Hi @SmithO
try the below code.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if(newValue == 'B') {
g_form.clearValue('sub_category','');
g_form.addOption('sub_category', '1', '1' );
g_form.addOption('sub_category', '2', '2' );
g_form.addOption('sub_category', '3', '3' );
g_form.addOption('sub_category', '5', '5' );
}else{
g_form.addOption('sub_category', '1', '1' );
g_form.addOption('sub_category', '2', '2' );
g_form.addOption('sub_category', '3', '3' );
g_form.addOption('sub_category', '4', '4' );
g_form.addOption('sub_category', '5', '5' );
}
Thanks
dgarad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2024 11:01 PM
Hi @SmithO ,
You can apply the onChange client script to achieve this. code is given below:
}var cat = g_form.getValue('category');
if (cat == 'B') {// cat ==backend value of category
// If category is selectes as ‘B’ then hide subcategory option ‘4’
g_form.removeOption('subcategory', '4');
}
Please accept my solution if it works for you and thumps up
Thanks
Jitendra