diff --git a/Client-Side Components/Client Scripts/Dynamic Reference Qualifier with Filtering/README.md b/Client-Side Components/Client Scripts/Dynamic Reference Qualifier with Filtering/README.md new file mode 100644 index 0000000000..351b9a5e92 --- /dev/null +++ b/Client-Side Components/Client Scripts/Dynamic Reference Qualifier with Filtering/README.md @@ -0,0 +1,6 @@ +**Dynamic Reference Qualifier with Filtering** +This Client Script provides a solution for dynamically updating the available options in a Reference Field based on the value selected in another field on the same form. + +This technique is essential for ensuring data quality and improving the user experience (UX). + +A typical use case is filtering the Assignment Group field to show only groups relevant to the selected Service, Category, or Location. diff --git a/Client-Side Components/Client Scripts/Dynamic Reference Qualifier with Filtering/reference_qual_dynamic.js b/Client-Side Components/Client Scripts/Dynamic Reference Qualifier with Filtering/reference_qual_dynamic.js new file mode 100644 index 0000000000..cc972cc534 --- /dev/null +++ b/Client-Side Components/Client Scripts/Dynamic Reference Qualifier with Filtering/reference_qual_dynamic.js @@ -0,0 +1,14 @@ + function onChange(control, oldValue, newValue, isLoading, isTemplate) { + if (isLoading || newValue === '') { + return; + } + var controlledField = 'assignment_group'; + var controllingField = 'u_service'; + var serviceSysId = g_form.getValue(controllingField); + var encodedQuery = 'typeLIKEITIL^u_related_service=' + serviceSysId; + g_form.setQuery(controlledField, encodedQuery); + var currentGroupSysId = g_form.getValue(controlledField); + if (currentGroupSysId && oldValue !== '' && currentGroupSysId !== '') { + g_form.setValue(controlledField, ''); + } +}