- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2022 04:04 AM
I have 2 fields from the form.
1. Model Category (Reference field)
2. Model Sub Category (Choice field)
We have below fields from the Model category value:
Computer
Mobile Device
Printer
Peripheral
Display hardware
Now, I want to list Model Sub Category (Choice field) based on the selection from Model Category (Reference field) field.
Ex: If the user selects Computer as a Model Category (Reference field) then I should see only below dropdown values from Model Sub Category (Choice field)
Desktop
Laptop
Gaming Console
How can I achieve this with the client script?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2022 04:08 AM - edited 10-19-2022 04:13 AM
Hi @Vijayr119
You can write onChange Client Script on Model Category field, and than using g_form.addOption() and g_form.removeOption() function, you can add drop down options for your Model Sub Category field.
Find sample code below:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var modCat = g_form.getValue('model_category');
if(modCat == '<sysid of Comupter>'){
g_form.addOption('model_sub_category', 'desktop', 'Desktop');
g_form.addOption('model_sub_category', 'laptop', 'Laptop');
g_form.addOption('model_sub_category', 'gaming_console', 'Gaming Console');
g_form.removeOption('model_sub_category','mobile');
g_form.removeOption('model_sub_category','ipad');
}
//.....
Please refer below link to know more about this functions:
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2022 04:08 AM - edited 10-19-2022 04:13 AM
Hi @Vijayr119
You can write onChange Client Script on Model Category field, and than using g_form.addOption() and g_form.removeOption() function, you can add drop down options for your Model Sub Category field.
Find sample code below:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var modCat = g_form.getValue('model_category');
if(modCat == '<sysid of Comupter>'){
g_form.addOption('model_sub_category', 'desktop', 'Desktop');
g_form.addOption('model_sub_category', 'laptop', 'Laptop');
g_form.addOption('model_sub_category', 'gaming_console', 'Gaming Console');
g_form.removeOption('model_sub_category','mobile');
g_form.removeOption('model_sub_category','ipad');
}
//.....
Please refer below link to know more about this functions:
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023