- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2024 08:45 AM
Hi All,
I need to display different sets of categories based on the selected Service field. I created an on-change client script for the Service field, and it works as expected when I initially choose a specific service, showing the relevant categories. However, if I change the service field again, the categories appear blank unless I refresh the page. Any thoughts?
The on-change client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var serviceName = g_form.getReference('business_service').name;
var optionsToRemove = [];
if (serviceName == 'AS HCI OS') {
optionsToRemove = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 270, 280, 290, 300, 310, 320, 330];
} else if (serviceName == 'AKS Hybrid') {
optionsToRemove = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 260, 310, 320, 330];
} else if (serviceName == 'Windows Server Support') {
optionsToRemove = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 260, 270, 280, 290, 300];
} else {
optionsToRemove = [170, 180, 190, 200, 210, 220, 230, 240, 250, 260, 270, 280, 290, 300, 310, 320, 330];
}
optionsToRemove.forEach(function(option) {
g_form.removeOption('category', option);
});
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2024 09:07 AM - edited 07-31-2024 10:21 AM
I guess you can go with Dependent fields rather than this On change code. Dependent field should work here.
Please mark my Answer as correct Answer and helpful if you think it helped you in anyways.
Regards,
Nikhil Bajaj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2024 10:19 AM - edited 07-31-2024 11:10 AM
Using dependent fields is a better approach for dynamically filtering the categories based on the selected service. This method is more efficient and provides a consistent user experience without the need for additional scripting. You can configure the dependency in the dictionary entry of the dependent field (e.g., "Category") to automatically filter options based on the selected value in another field (e.g., "Service"). This way, only relevant categories are shown based on the selected service, streamlining the process and ensuring accuracy.
…………………………………………........................................................................................
Mark it helpful 👍and Accept Solution ✅!! If this helps you to understand.
…………………………………………........................................................................................

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2024 09:00 AM
Instead of removing options I would do the following logic. As your is just removing option.
1. Clear all option from category g_form.clearOptions
2. I would then use g_form.addOption to add the option needed for the selected service.
This will clear out all options every time someone changes the service and then add only the ones needed for that service.
You may also want to do this with a client callable script include. In case you have to do this on other task types. That way you only need to call the script include.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2024 09:07 AM - edited 07-31-2024 10:21 AM
I guess you can go with Dependent fields rather than this On change code. Dependent field should work here.
Please mark my Answer as correct Answer and helpful if you think it helped you in anyways.
Regards,
Nikhil Bajaj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2024 02:53 AM
Thank you all for your support! I wasn’t aware of the Dependent field, which has partially resolved the issue. Now, the relevant categories are populated based on the service configured in the Dependent field. However, there are about 10 categories that need to be associated with more than one service. Is there a solution for this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2024 10:19 AM - edited 07-31-2024 11:10 AM
Using dependent fields is a better approach for dynamically filtering the categories based on the selected service. This method is more efficient and provides a consistent user experience without the need for additional scripting. You can configure the dependency in the dictionary entry of the dependent field (e.g., "Category") to automatically filter options based on the selected value in another field (e.g., "Service"). This way, only relevant categories are shown based on the selected service, streamlining the process and ensuring accuracy.
…………………………………………........................................................................................
Mark it helpful 👍and Accept Solution ✅!! If this helps you to understand.
…………………………………………........................................................................................