Show dependant sub cats on a ui action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2025 01:06 AM
I have wrote this script in a UI action to resolve a ticket. I have listed all of my categories on it. The question I have is how do I get it so the dependent sub categories will show based on the category selected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2025 02:49 AM
This is the script I forgot to add
function onClick(g_form) {
var fields = [
{
type: 'choice',
name: 'u_closure_category',
label: getMessage('Closure category'),
value: getMessage(' -- Select -- '),
choices: [
{ displayValue: '3 strike rule', value: '3_strike_rule' },
{ displayValue: 'Access and permissions', value: 'access_and_permissions' },
{ displayValue: 'Applications', value: 'applications' },
{ displayValue: 'Data', value: 'data' },
{ displayValue: 'Data Protection', value: 'data_protection' },
{ displayValue: 'Digital', value: 'digital' },
{ displayValue: 'Email', value: 'email' },
{ displayValue: 'Engineer visit', value: 'engineer_visit' },
{ displayValue: 'Financial', value: 'financial' },
{ displayValue: 'Hardware', value: 'hardware' },
{ displayValue: 'Incorrect log', value: 'incorrect_log' },
{ displayValue: 'Information and Assistance', value: 'information_and_assistance' },
{ displayValue: 'Install', value: 'install' },
{ displayValue: 'Meeting room technology', value: 'meeting_room_technology' },
{ displayValue: 'Mobile Device Line and Data', value: 'mobile_device_line_and_data' },
{ displayValue: 'Network', value: 'network' },
{ displayValue: 'Onsite Telephony', value: 'onsite_telephony' },
{ displayValue: 'Printer', value: 'printer' },
{ displayValue: 'Server', value: 'server' },
{ displayValue: 'Shared drive/ repository', value: 'shared_drive_repository' },
{ displayValue: 'Telematics', value: 'telematics' },
{ displayValue: 'User Lifecycle management', value: 'user_lifecycle_management' }
],
mandatory: true
},
{
type: 'choice',
name: 'u_closure_sub_category',
label: getMessage('Closure sub-category'),
value: getMessage(' -- Select -- '),
choices: [
{ displayValue: 'General', value: 'general' },
{ displayValue: 'Issue', value: 'issue' },
{ displayValue: 'Request', value: 'request' }
],
mandatory: true
},
{
type: 'choice',
name: 'u_resolution_code',
label: getMessage('Resolution code'),
value: getMessage(' -- Select -- '),
choices: [
{ displayValue: 'Kit collected', value: 'kit_collected' },
{ displayValue: 'Kit not collected', value: 'kit_not_collected' },
{ displayValue: 'Order processed', value: 'order_processed' },
{ displayValue: 'Duplicate', value: 'duplicate' },
{ displayValue: 'Incorrect ticket type', value: 'incorrect_ticket_type' },
{ displayValue: 'Not resolved (not reproducible)', value: 'not_resolved_not_reproducible' },
{ displayValue: 'Not resolved (problem raised)', value: 'not_resolved_problem_raised' },
{ displayValue: 'Not resolved (too costly)', value: 'not_resolved_too_costly' },
{ displayValue: 'Resolved by caller', value: 'resolved_by_caller' },
{ displayValue: 'Resolved on site (Permanently)', value: 'resolved_on_site_permanently' },
{ displayValue: 'Resolved on site (Work Around)', value: 'resolved_on_site_work_around' },
{ displayValue: 'Resolved remotely (Permanently)', value: 'resolved_remotely_permanently' },
{ displayValue: 'Resolved remotely (Work Around)', value: 'resolved_remotely_work_around' }
],
mandatory: true
},
{
type: 'textarea',
name: 'close_notes',
label: getMessage('Close notes'),
mandatory: true
}
];
g_modal.showFields({
title: "Enter closure information",
fields: fields,
size: 'lg'
}).then(function(fieldValues) {
g_form.setValue('u_closure_category', fieldValues.updatedFields[0].value);
g_form.setValue('u_closure_sub_category', fieldValues.updatedFields[1].value);
g_form.setValue('u_resolution_code', fieldValues.updatedFields[2].value);
g_form.setValue('close_notes', fieldValues.updatedFields[3].value);
// Set the request_state to 'resolved'
g_form.setValue('request_state', 'resolved');
g_form.save();
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2025 02:51 AM
please share script, screenshots etc
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
‎07-15-2025 02:59 AM
This is the script
function onClick(g_form) {
var fields = [
{
type: 'choice',
name: 'u_closure_category',
label: getMessage('Closure category'),
value: getMessage(' -- Select -- '),
choices: [
{ displayValue: '3 strike rule', value: '3_strike_rule' },
{ displayValue: 'Access and permissions', value: 'access_and_permissions' },
{ displayValue: 'Applications', value: 'applications' },
{ displayValue: 'Data', value: 'data' },
{ displayValue: 'Data Protection', value: 'data_protection' },
{ displayValue: 'Digital', value: 'digital' },
{ displayValue: 'Email', value: 'email' },
{ displayValue: 'Engineer visit', value: 'engineer_visit' },
{ displayValue: 'Financial', value: 'financial' },
{ displayValue: 'Hardware', value: 'hardware' },
{ displayValue: 'Incorrect log', value: 'incorrect_log' },
{ displayValue: 'Information and Assistance', value: 'information_and_assistance' },
{ displayValue: 'Install', value: 'install' },
{ displayValue: 'Meeting room technology', value: 'meeting_room_technology' },
{ displayValue: 'Mobile Device Line and Data', value: 'mobile_device_line_and_data' },
{ displayValue: 'Network', value: 'network' },
{ displayValue: 'Onsite Telephony', value: 'onsite_telephony' },
{ displayValue: 'Printer', value: 'printer' },
{ displayValue: 'Server', value: 'server' },
{ displayValue: 'Shared drive/ repository', value: 'shared_drive_repository' },
{ displayValue: 'Telematics', value: 'telematics' },
{ displayValue: 'User Lifecycle management', value: 'user_lifecycle_management' }
],
mandatory: true
},
{
type: 'choice',
name: 'u_closure_sub_category',
label: getMessage('Closure sub-category'),
value: getMessage(' -- Select -- '),
choices: [
{ displayValue: 'General', value: 'general' },
{ displayValue: 'Issue', value: 'issue' },
{ displayValue: 'Request', value: 'request' }
],
mandatory: true
},
{
type: 'choice',
name: 'u_resolution_code',
label: getMessage('Resolution code'),
value: getMessage(' -- Select -- '),
choices: [
{ displayValue: 'Kit collected', value: 'kit_collected' },
{ displayValue: 'Kit not collected', value: 'kit_not_collected' },
{ displayValue: 'Order processed', value: 'order_processed' },
{ displayValue: 'Duplicate', value: 'duplicate' },
{ displayValue: 'Incorrect ticket type', value: 'incorrect_ticket_type' },
{ displayValue: 'Not resolved (not reproducible)', value: 'not_resolved_not_reproducible' },
{ displayValue: 'Not resolved (problem raised)', value: 'not_resolved_problem_raised' },
{ displayValue: 'Not resolved (too costly)', value: 'not_resolved_too_costly' },
{ displayValue: 'Resolved by caller', value: 'resolved_by_caller' },
{ displayValue: 'Resolved on site (Permanently)', value: 'resolved_on_site_permanently' },
{ displayValue: 'Resolved on site (Work Around)', value: 'resolved_on_site_work_around' },
{ displayValue: 'Resolved remotely (Permanently)', value: 'resolved_remotely_permanently' },
{ displayValue: 'Resolved remotely (Work Around)', value: 'resolved_remotely_work_around' }
],
mandatory: true
},
{
type: 'textarea',
name: 'close_notes',
label: getMessage('Close notes'),
mandatory: true
}
];
g_modal.showFields({
title: "Enter closure information",
fields: fields,
size: 'lg'
}).then(function(fieldValues) {
g_form.setValue('u_closure_category', fieldValues.updatedFields[0].value);
g_form.setValue('u_closure_sub_category', fieldValues.updatedFields[1].value);
g_form.setValue('u_resolution_code', fieldValues.updatedFields[2].value);
g_form.setValue('close_notes', fieldValues.updatedFields[3].value);
// Set the request_state to 'resolved'
g_form.setValue('request_state', 'resolved');
g_form.save();
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2025 03:10 AM
you can try this, I haven't tried this approach
1) have the category choices
2) have onchange event for each of those category choices, and call a method and pass the category value. This is tricky
3) use GlideAjax in that method and get the dependent subcategories
4) then add the choices which you get from script include and dynamically populate them
refer my blog
Populating dynamic choices in workspace form pane for choice field type
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