Filtering choice field options based on a multi-select parent field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi everyone,
I’m working on a form in ServiceNow (standard table form, not Service Catalog) and I’m trying to understand whether a specific requirement is technically possible.
Scenario
I have a field called record_type
Type: List (multi-select choice)
Example values: type_a, type_b, type_c
I also have a field called category
Type: Choice
This field contains all category options for all record types
Requirement
If record_type = type_a, the Category field should show only categories related to type_a
If record_type = type_b, it should show only categories related to type_b
If multiple values are selected (for example type_a and type_b), the Category field should show the combined set of categories for both
If nothing is selected, ideally no category options should be available
Is there any solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Due to the multiple selections/combinations, a simple dependency won't work. You'll need a Client Script similar to this onChange of the record_type variable. With each value selected, the choice list will be wiped out then each valid choice is added based on your logic for the record type(s) selected.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
g_form.clearOptions('category');
var recTypeArr = newValue.toString().split(',');
for (var i = 0; i < recTypeArr.length; i++) {
//add an if block for each record_type value
if (recTypeArr[i] == '0a52d3dcd7011200f2d224837e6103f2') { //sys_id of the record from the list table
//add a line for each choice for this record_type
g_form.addOption('category', 'cat_value', 'cat_string');
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Thanks for the suggestion. Just to confirm, this field is a dictionary-based table field (not a Service Catalog variable). My understanding is that g_form.addOption() is supported for catalog variables but not for table choice fields. Can you confirm if this approach is supported in that context as well?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
approach from @Brad Bowman should work
Try that and share feedback
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
