How to make a Subcategory dependent on a category in catalog item?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi All,
we have Category and Subcategory variables, Select Box type variables in catalog item. I want to make a subcategories choices dependent on category choices. How do I achieve this? Please refer below screenshots.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
To make “Subcategory” choices dependent on the selection of “Category” in ServiceNow catalog items, you should implement a dynamic dependent selection using Catalog Client Scripts or reference qualifiers on your variable set.
Firstly start with Reference Qualifier Setup
Set a reference qualifier for the Subcategory variable based on the selected value in the Category variable.
For Select Box variables, use the Catalog Client Script approach since reference qualifiers are primarily for reference fields.
Then Use Catalog Client Script
Create an ‘onChange’ Catalog Client Script on the ‘Category’ variable. Create a new client script of type "OnChange"
if (isLoading || newValue == '') {
g_form.clearOptions('subcategory');
return;
}
var subcategoryMap = {
'Other': ['System Functionality', 'Creation of local Job Self-Family'],
'Edit Existing Localized Content': ['System Functionality'],
'Creation of localized Job Profile': ['Job Family', 'Role Profile'],
// Add all your mappings here
};
g_form.clearOptions('subcategory');
var subs = subcategoryMap[newValue];
if (subs && subs.length) {
for (var i = 0; i < subs.length; i++) {
g_form.addOption('subcategory', subs[i], subs[i]);
}
}
}
Adjust the `subcategoryMap` definition to match your values as seen in your screenshots.
By following the above steps, the subcategory list will automatically update based on the selected category, as requested.
This is the dynamic solution which will work in your scenario there can be other ways as well to achieve this but this will definitely work in your case. Let me know if you want to try other ways to achieve it or let me know if you want more information on this.
If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.
Best regards,
Madhan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@The Matrix If you want to do this which choice variable follow:
Another method:
Please mark the answer correct/helpful accordingly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@The Matrix did this solution work for you?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I shared solution here few months ago which also handles the choices displayed based on language
check and enhance
Wants to remove duplicates from my lookup select box for category and subcategory
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
