Restrict list choices based on multiple fields
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2024 06:07 AM - edited ‎04-10-2024 06:13 AM
Hey all,
I've been trying to make this work for a day or so and can't get the results I'm looking for.
It's simple to restrict the choices in a list field based on a dependent field. Category and Subcategory are already setup for this functionality, but I need a way to restrict the Subcategory field based on both the Category field and the Incident Type field.
I have two Incident Types: Dental and IT. I've already restricted the categories available based on the Incident type that is chosen, but I then need to restrict the subcategories based on this as well. So, if I choose Dental as the incident type and Hardware as the category, I only want a specific set of choices from the list of choices available under Hardware. Because Hardware is a choice for both Dental and IT Incident Types, I'm always getting all choices for Hardware under both Dental and IT.
I've tried using a Business Rule and a Client Script on the Incident table, but neither are doing what I need.
Client Script that I've tried:
function onChange() {
var category = g_form.getValue('category');
var type = g_form.getValue('u_incident_type');
if (type == 'Dental') {
alert('Help');
if (category == 'Hardware') {
g_form.clearOptions('subcategory');
g_form.addOption('subcategory', 'Computer', 'Computer');
}
}
}
The alert works, so I know the script is running, but it's not clearing the options. I can see that it is acting on the subcategory because it sets the value to Computer, but the other options are still there.
Also, I need this to work in the Service Portal as well.
Any help is much appreciated.
I've also posted this question on reddit.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2024 06:40 AM
That's right... it will be a long script because, based on the selection, you need to use removeOption & addOption and adding after removing will add the choice at the bottom. So for every selection change, you would be clearing all options and adding the required in sequence you need...
Why not make Category and Subcategory both dependent on Incident Type?
Or may be create a custom lookup table with the mapping of Incident Type/Category/Subcategory and use it to show hide choices.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2024 07:26 AM
I haven't tried making both dependent on Incident Type. I will give that a go.
I've never created a custom lookup table. I'll try that as well.
Thanks for the suggestions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2024 06:29 AM
It really seems like there is something else in the system that is overwriting what the client script does. If you read the Reddit post, it seems like there is something that is overwriting what the script is doing almost immediately after it runs. I tried using a UI policy and adjusted the Order to over 1000, and that still doesn't seem to work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2024 01:07 PM
Update: I got it working finally. It still doesn't seem to work in the Service Portal though.
So far I have an onChange Client Script on the Subcategory field. Here is my code so far.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
if(newValue == '') {
if (g_form.getValue('category') == 'Hardware' && g_form.getValue('u_incident_type') == 'Dental') {
g_form.clearOptions('subcategory');
g_form.addOption('subcategory', 'Computer', 'Computer');
g_form.addOption('subcategory', 'Document Scanner', 'Document Scanner');
g_form.addOption('subcategory', 'Intraoral Scanner', 'Intraoral Scanner');
g_form.addOption('subcategory', 'Topaz Signature Pad', 'Topaz Signature Pad');
g_form.addOption('subcategory', 'X-Ray', 'X-Ray');
g_form.addOption('subcategory', '3D Scanner', '3D Scanner');
}
}
}
This is working in the backend\instance version of the Incident form. Glad I've made some progress cause this was driving me nuts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2024 02:56 AM
Hi @JB6
Could you please verify that UI type should be set to "ALL"
SS - 1
If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.
Thanks,
Subhashis Ratna