Reference fields dependency
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2025 02:12 AM
How to set one dependent field on another. Like we have 'class' field and another is 'sub-class' but subclass field should be dependent on the class field. These two fields are reference type and also we have tried the option of the dependency from the field dictionary but it is not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2025 02:23 AM
Hi @ShivamS44129005 ,
In reference qualifier of sub-class dictionary put below code.
javascript: "u_class=" + current.u_class;
Assuming u_class field is present on sub-class reference table.
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2025 02:28 AM
Create a Client Script (onChange) for the class field to dynamically filter the available sub-class options.
function onChange(control, oldValue, newValue, isLoading) {
// Exit if the form is loading
if (isLoading) return;
// Clear the current options for the `sub-class` field
g_form.clearOptions('sub_class');
// If a `class` value is selected, filter `sub-class` options based on the class
if (newValue) {
var gr = new GlideRecord('your_class_to_subclass_table'); // A table that links 'class' to 'sub-class'
gr.addQuery('class', newValue); // Query based on the selected class
gr.query();
// Loop through the records and add options to the `sub-class` field
while (gr.next()) {
g_form.addOption('sub_class', gr.sub_class, gr.sub_class.name); // Add the subclass option
}
}
}
I hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.
thank you
Rajesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2025 02:30 AM
Hi @ShivamS44129005 ,
since both the fields are of type reference, you can use a reference qualifier on the other field to return the list based on the first reference field.
Regards,
Bhavani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2025 02:39 AM
please share some details
1) both the field refer to which table
2) what's your exact requirement to filter
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader