How to add category based on sub category
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2025 02:21 AM
Hi All,
I have created 1 catalog item in witch I have multiple category & sub category both are select box choice, in witch subcategory should populated based on category kindly let me know how to do it.
Thanks & Regards
KP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2025 02:56 AM
Hi @keval3
Not clear on your issue but look like
you want to show the sub cat based on selection of Cat.
You can use the catalog UI policy and show based on same or if you can share the screenshot that will be good.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2025 03:00 AM
Hello @keval3 ,
You can try something like the below onChange client script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
// Clear existing options in Subcategory
g_form.clearOptions('subcategory'); // Replace 'subcategory' with your field name
// Add a default "Select Subcategory" option
g_form.addOption('subcategory', '', '--Select Subcategory--');
// Define the mapping between Categories and Subcategories
var subcategoryOptions = {
'Hardware': ['Laptops', 'Desktops', 'Printers'],
'Software': ['Operating System', 'Productivity Tools', 'Security Software'],
'Networking': ['Switches', 'Routers', 'Firewalls']
};
// Get the subcategories for the selected category
var subcategories = subcategoryOptions[newValue] || [];
// Add the subcategories as options
subcategories.forEach(function(subcategory) {
g_form.addOption('subcategory', subcategory, subcategory);
});
}
Adjust the code as per your requirement.
Please mark this as "correct" and "helpful" if you feel this answer helped you in anyway.
Thanks and Regards,
Ashish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2025 04:40 AM
why not make them dependent so that subcategories are shown based on category selected?
This is similar to how incident form works
check these links for the solution or workaround
Category-Subcategory dependency in Service Catalog (Make variables dependent without scripting)
Dependent variable on Catalog item
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
‎01-07-2025 07:12 PM
Hope you are doing good.
Did my reply answer your question?
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