- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2025 07:04 AM
Hi All,
There are 2 variable in serviceportal 1 Hr Category & Hr subcategory, HR subcategory are base on hr category, both are select box variable with None. but when I select category at that time HR subcategory will automatically populated with out none it should be none. I have written below catalog client script. on change of category variable.
Thanks & Regards
KP
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2025 07:57 AM
Assuming the choice values for the HR category in JSON are correctly configured and the choice labels and choice values in that json for sub category is correct configured
update script as this
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.clearOptions('hr_subcategory');
alert(g_form.getValue('hr_category'));
var dependencies = {
'Learning & Development (L&D)': [{
value: 'User Creation/Deletion',
label: 'User Creation/Deletion'
},
{
value: 'Login issues',
label: 'Login issues'
},
{
value: 'reports',
label: 'reports'
},
],
'Talent Management': [
//{ value: 'none', label: 'none' },
{
value: 'User Creation/Deletion',
label: 'User Creation/Deletion'
},
{
value: 'Login issues',
label: 'Login issues'
},
{
value: 'reports',
label: 'reports'
},
{
value: 'Compliance course',
label: 'Compliance course'
},
{
value: 'Talent Review',
label: 'Talent Review'
},
{
value: 'Calibration',
label: 'Calibration'
},
{
value: 'Metrics Review',
label: 'Metrics Review'
},
{
value: 'Online courses',
label: 'Online courses'
}
],
'Employee Data Management (EDM)': [
//{ value: 'none', label: 'none' },
{
value: 'UGDN creation',
label: 'UGDN creation'
},
{
value: 'Position ID creation',
label: 'Position ID creation'
},
{
value: 'SAP ID creation',
label: 'SAP ID creation'
},
{
value: 'Transfer',
label: 'Transfer'
},
{
value: 'Promotion',
label: 'Promotion'
},
{
value: 'Termination',
label: 'Termination'
},
{
value: 'HR Letter',
label: 'HR Letter'
},
{
value: 'Reports',
label: 'Reports'
},
{
value: 'Personal Details Change',
label: 'Personal Details Change'
},
{
value: 'Work Details Change',
label: 'Work Details Change'
}
]
};
// Add the "None" option
// Add the "None" option
g_form.addOption('hr_subcategory', '', '-- None --');
// Populate the subcategories based on the selected category
var selectedCategory = g_form.getValue('hr_category');
if (dependencies[selectedCategory]) {
dependencies[selectedCategory].forEach(function(subcategory) {
g_form.addOption('hr_subcategory', subcategory.value, subcategory.label);
});
}
}
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-08-2025 07:26 AM
seems you didn't share the complete code
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-08-2025 07:57 AM
Assuming the choice values for the HR category in JSON are correctly configured and the choice labels and choice values in that json for sub category is correct configured
update script as this
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.clearOptions('hr_subcategory');
alert(g_form.getValue('hr_category'));
var dependencies = {
'Learning & Development (L&D)': [{
value: 'User Creation/Deletion',
label: 'User Creation/Deletion'
},
{
value: 'Login issues',
label: 'Login issues'
},
{
value: 'reports',
label: 'reports'
},
],
'Talent Management': [
//{ value: 'none', label: 'none' },
{
value: 'User Creation/Deletion',
label: 'User Creation/Deletion'
},
{
value: 'Login issues',
label: 'Login issues'
},
{
value: 'reports',
label: 'reports'
},
{
value: 'Compliance course',
label: 'Compliance course'
},
{
value: 'Talent Review',
label: 'Talent Review'
},
{
value: 'Calibration',
label: 'Calibration'
},
{
value: 'Metrics Review',
label: 'Metrics Review'
},
{
value: 'Online courses',
label: 'Online courses'
}
],
'Employee Data Management (EDM)': [
//{ value: 'none', label: 'none' },
{
value: 'UGDN creation',
label: 'UGDN creation'
},
{
value: 'Position ID creation',
label: 'Position ID creation'
},
{
value: 'SAP ID creation',
label: 'SAP ID creation'
},
{
value: 'Transfer',
label: 'Transfer'
},
{
value: 'Promotion',
label: 'Promotion'
},
{
value: 'Termination',
label: 'Termination'
},
{
value: 'HR Letter',
label: 'HR Letter'
},
{
value: 'Reports',
label: 'Reports'
},
{
value: 'Personal Details Change',
label: 'Personal Details Change'
},
{
value: 'Work Details Change',
label: 'Work Details Change'
}
]
};
// Add the "None" option
// Add the "None" option
g_form.addOption('hr_subcategory', '', '-- None --');
// Populate the subcategories based on the selected category
var selectedCategory = g_form.getValue('hr_category');
if (dependencies[selectedCategory]) {
dependencies[selectedCategory].forEach(function(subcategory) {
g_form.addOption('hr_subcategory', subcategory.value, subcategory.label);
});
}
}
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-08-2025 08:32 AM