- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2025 10:41 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2025 07:11 AM
subcategory is dependent on category
When you select category subcategory will show dependent values.
what's not working as expected?
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2025 08:31 AM
Hello @ravitejak
Hope you are doing well!
First thing is, you can use the Dependent Value functionality to achieve this requirement. If you are using OnChange client script and it giving error then please share here.
Below is my sample script in which I have created Category and Subcategory fields and written the onchange client script with addOption() and removeOption() methods. You can customize the script as per your field data:
OnChange Client Script:
Type: Onchange
Field Name: Category
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
g_form.removeOption('u_subcategory', 'Chrome', 'Chrome');
g_form.removeOption('u_subcategory', 'iTune', 'iTune');
g_form.removeOption('u_subcategory', 'USB', 'USB');
g_form.removeOption('u_subcategory', 'Mouse', 'Mouse');
return;
}
//alert(newValue);
if (newValue == 'Software') {
g_form.addOption('u_subcategory', 'Chrome', 'Chrome');
g_form.addOption('u_subcategory', 'iTune', 'iTune');
g_form.removeOption('u_subcategory', 'USB', 'USB');
g_form.removeOption('u_subcategory', 'Mouse', 'Mouse');
} else if (newValue == 'Hardware') {
g_form.addOption('u_subcategory', 'USB', 'USB');
g_form.addOption('u_subcategory', 'Mouse', 'Mouse');
g_form.removeOption('u_subcategory', 'Chrome', 'Chrome');
g_form.removeOption('u_subcategory', 'iTune', 'iTune');
}
}
Please let me know in case you need help with this requirement
Thank you!
Thank You!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2025 07:11 AM
subcategory is dependent on category
When you select category subcategory will show dependent values.
what's not working as expected?
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2025 08:31 AM
Hello @ravitejak
Hope you are doing well!
First thing is, you can use the Dependent Value functionality to achieve this requirement. If you are using OnChange client script and it giving error then please share here.
Below is my sample script in which I have created Category and Subcategory fields and written the onchange client script with addOption() and removeOption() methods. You can customize the script as per your field data:
OnChange Client Script:
Type: Onchange
Field Name: Category
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
g_form.removeOption('u_subcategory', 'Chrome', 'Chrome');
g_form.removeOption('u_subcategory', 'iTune', 'iTune');
g_form.removeOption('u_subcategory', 'USB', 'USB');
g_form.removeOption('u_subcategory', 'Mouse', 'Mouse');
return;
}
//alert(newValue);
if (newValue == 'Software') {
g_form.addOption('u_subcategory', 'Chrome', 'Chrome');
g_form.addOption('u_subcategory', 'iTune', 'iTune');
g_form.removeOption('u_subcategory', 'USB', 'USB');
g_form.removeOption('u_subcategory', 'Mouse', 'Mouse');
} else if (newValue == 'Hardware') {
g_form.addOption('u_subcategory', 'USB', 'USB');
g_form.addOption('u_subcategory', 'Mouse', 'Mouse');
g_form.removeOption('u_subcategory', 'Chrome', 'Chrome');
g_form.removeOption('u_subcategory', 'iTune', 'iTune');
}
}
Please let me know in case you need help with this requirement
Thank you!
Thank You!