- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 09:50 PM
I have 2 reference fields in a catalog item. Both refers to different tables. I want to display second field's choices based on the first field choice selection.
field1: issue - issue table
field 2 issue subcategory - issue subcategory table.
issue is a common field in both the custom tables which refers to issue master table.
How can I achieve this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 11:14 PM
Hi @Shrivatsa Hegde ,
You can write a script include and call it in reference qualifier. I have done the same for category and sub-category I have attached the screenshot below.Script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 11:45 PM
HI @Shrivatsa Hegde ,
I trust you are doing great.
Please find the below catalog client script code
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var field1Value = g_form.getValue('field1'); // Get the value of the first reference field.
// Clear the choices in field 2.
g_form.clearOptions('field2');
if (field1Value) {
// Query the issue subcategory records based on the selected issue.
var gr = new GlideRecord('issue_subcategory');
gr.addQuery('issue', field1Value);
gr.query();
// Populate the choices in field 2 with the matching issue subcategories.
while (gr.next()) {
var value = gr.getUniqueValue();
var displayValue = gr.getValue('name'); // Replace 'name' with the display field in the issue subcategory table.
g_form.addOption('field2', value, displayValue);
}
}
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 11:14 PM
Hi @Shrivatsa Hegde ,
You can write a script include and call it in reference qualifier. I have done the same for category and sub-category I have attached the screenshot below.Script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 11:45 PM
HI @Shrivatsa Hegde ,
I trust you are doing great.
Please find the below catalog client script code
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var field1Value = g_form.getValue('field1'); // Get the value of the first reference field.
// Clear the choices in field 2.
g_form.clearOptions('field2');
if (field1Value) {
// Query the issue subcategory records based on the selected issue.
var gr = new GlideRecord('issue_subcategory');
gr.addQuery('issue', field1Value);
gr.query();
// Populate the choices in field 2 with the matching issue subcategories.
while (gr.next()) {
var value = gr.getUniqueValue();
var displayValue = gr.getValue('name'); // Replace 'name' with the display field in the issue subcategory table.
g_form.addOption('field2', value, displayValue);
}
}
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi