- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2023 02:57 AM - edited 08-11-2023 03:00 AM
Hello guys,
I have three 2 Lookup Select Box and one Select Box
1. Equipment (Lookup Select Box) - (Referenced appropriate table)
2. Brand (Lookup Select Box) - (Referenced appropriate table)
3. Model (Select Box)
My expectation is, when I select Computer in the 1st select box, the 2nd select box will display appropriate options.
The same for the 2nd select box and the 3rd select box.
However, my code is not working as below.
I'm using "Catalog Client Scripts" with Type : onChange settings
Or any other method is better to achieve this?
Thanks Bros!!!
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var gr = new GlideRecord('u_cmdb_ci_second_option');
if (newValue == 'Computer') {
g_form.clearOptions('second_options');
gr.addQuery('name', 'Computer');
gr.query();
while (gr.next()) {
g_form.addOption('second_options', gr.getValue('name'), gr.getValue('name'));
//g_form.addOption('second_options', gr.name, gr.name); <-- Also tried
}
g_form.addOption('second_options', 'other', 'Others - Computer');
} else if (newValue == 'TV') {
g_form.clearOptions('second_options');
gr.addQuery('model', 'TV');
gr.query();
while (gr.next()) {
g_form.addOption('second_options', gr.getValue('name'), gr.getValue('name'));
//g_form.addOption('second_options', gr.name, gr.name); <-- Also tried
g_form.addOption('second_options', 'other', 'Others - TV');
}
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2023 03:12 AM - edited 08-20-2023 10:53 PM
Hello @Wing Lee1 ,
Using Glide record in client script is not a best practice as it is a server side API .
please shift the glide record logic to script include and then return set of options in an array and then loop the array using for loop and then add the options
syntax would be
g_form.addOption('variable_name', 'choice_1_backned_name', 'Choice1_label);
Hope this helps
Mark my answer correct if this helps you
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2023 03:12 AM - edited 08-20-2023 10:53 PM
Hello @Wing Lee1 ,
Using Glide record in client script is not a best practice as it is a server side API .
please shift the glide record logic to script include and then return set of options in an array and then loop the array using for loop and then add the options
syntax would be
g_form.addOption('variable_name', 'choice_1_backned_name', 'Choice1_label);
Hope this helps
Mark my answer correct if this helps you
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2023 07:43 PM
Thank you Mohith.
Let me try.