Dependent values getting erased if we are using g_form.removeOption for onchange client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 06:26 AM
I have two variables, request type and subrequest type. values of sub request type are dependent on request type. Now I have added all the question choices for sub request type and using g_form.removeOption to hide the values based on selected requested type value. But for the first selection of request type i am getting the desired sub request type values, but for subsequent slections i am not able to see any values in sub request type.
Any one can help please
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 07:31 AM
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
//g_form.clearOptions('request_sub_type');
// g_form.addOption('request_sub_type', '', '-- None --');
return;
}
if (g_form.getValue('request_type') == 'service_request') {
g_form.
g_form.removeOption('request_sub_type', 'resource_allocation');
g_form.removeOption('request_sub_type', 'performance_monitoring');
g_form.removeOption('request_sub_type', 'capacity_planning');
g_form.removeOption('request_sub_type', 'scalability_requests');
g_form.removeOption('request_sub_type', 'vulnerability_management');
g_form.removeOption('request_sub_type', 'compliance_request');
g_form.removeOption('request_sub_type', 'configuration_changes');
g_form.removeOption('request_sub_type', 'deployments');
g_form.removeOption('request_sub_type', 'schedule_maintenance');
g_form.removeOption('request_sub_type', 'system_outage');
g_form.removeOption('request_sub_type', 'network_issues');
g_form.removeOption('request_sub_type', 'hardware_failures');
g_form.removeOption('request_sub_type', 'application_errors');
g_form.addOption('request_sub_type', 'hardware_provisioning');
g_form.addOption('request_sub_type', 'access_management');
g_form.addOption('request_sub_type', 'software_installation');
g_form.addOption('request_sub_type', 'network_requests');
g_form.addOption('request_sub_type', 'information_request');
g_form.addOption('request_sub_type', 'onboarding');
} else if (g_form.getValue('request_type') == 'capacity_management') {
g_form.addOption('request_sub_type', 'resource_allocation');
g_form.addOption('request_sub_type', 'performance_monitoring');
g_form.addOption('request_sub_type', 'capacity_planning');
g_form.addOption('request_sub_type', 'scalability_requests');
g_form.removeOption('request_sub_type', 'vulnerability_management');
g_form.removeOption('request_sub_type', 'compliance_request');
g_form.removeOption('request_sub_type', 'configuration_changes');
g_form.removeOption('request_sub_type', 'deployments');
g_form.removeOption('request_sub_type', 'schedule_maintenance');
g_form.removeOption('request_sub_type', 'system_outage');
g_form.removeOption('request_sub_type', 'network_issues');
g_form.removeOption('request_sub_type', 'hardware_failures');
g_form.removeOption('request_sub_type', 'application_errors');
g_form.removeOption('request_sub_type', 'hardware_provisioning');
g_form.removeOption('request_sub_type', 'access_management');
g_form.removeOption('request_sub_type', 'software_installation');
g_form.removeOption('request_sub_type', 'network_requests');
g_form.removeOption('request_sub_type', 'information_request');
g_form.removeOption('request_sub_type', 'onboarding');
} else if (g_form.getValue('request_type') == 'security_management') {
g_form.addOption('request_sub_type', 'vulnerability_management');
g_form.addOption('request_sub_type', 'compliance_request');
g_form.removeOption('request_sub_type', 'resource_allocation');
g_form.removeOption('request_sub_type', 'performance_monitoring');
g_form.removeOption('request_sub_type', 'capacity_planning');
g_form.removeOption('request_sub_type', 'scalability_requests');
g_form.removeOption('request_sub_type', 'hardware_provisioning');
g_form.removeOption('request_sub_type', 'configuration_changes');
g_form.removeOption('request_sub_type', 'deployments');
g_form.removeOption('request_sub_type', 'schedule_maintenance');
g_form.removeOption('request_sub_type', 'system_outage');
g_form.removeOption('request_sub_type', 'network_issues');
g_form.removeOption('request_sub_type', 'hardware_failures');
g_form.removeOption('request_sub_type', 'application_errors');
g_form.removeOption('request_sub_type', 'hardware_provisioning');
g_form.removeOption('request_sub_type', 'access_management');
g_form.removeOption('request_sub_type', 'software_installation');
g_form.removeOption('request_sub_type', 'network_requests');
g_form.removeOption('request_sub_type', 'information_request');
g_form.removeOption('request_sub_type', 'onboarding');
} else if (g_form.getValue('request_type') == 'change_management') {
g_form.addOption('request_sub_type', 'configuration_changes');
g_form.addOption('request_sub_type', 'deployments');
g_form.addOption('request_sub_type', 'schedule_maintenance');
g_form.removeOption('request_sub_type', 'resource_allocation');
g_form.removeOption('request_sub_type', 'hardware_provisioning');
g_form.removeOption('request_sub_type', 'resource_allocation');
g_form.removeOption('request_sub_type', 'performance_monitoring');
g_form.removeOption('request_sub_type', 'capacity_planning');
g_form.removeOption('request_sub_type', 'scalability_requests');
g_form.removeOption('request_sub_type', 'hardware_provisioning');
g_form.removeOption('request_sub_type', 'system_outage');
g_form.removeOption('request_sub_type', 'network_issues');
g_form.removeOption('request_sub_type', 'hardware_failures');
g_form.removeOption('request_sub_type', 'application_errors');
g_form.removeOption('request_sub_type', 'hardware_provisioning');
g_form.removeOption('request_sub_type', ' access_management');
g_form.removeOption('request_sub_type', 'software_installation');
g_form.removeOption('request_sub_type', 'network_requests');
g_form.removeOption('request_sub_type', 'information_request');
g_form.removeOption('request_sub_type', 'onboarding');
g_form.removeOption('request_sub_type', 'vulnerability_management');
g_form.removeOption('request_sub_type', 'compliance_request');
} else if (g_form.getValue('request_type') == 'lower_env_sprt') {
g_form.addOption('request_sub_type', 'system_outage');
g_form.addOption('request_sub_type', 'network_issues');
g_form.addOption('request_sub_type', 'hardware_failures');
g_form.addOption('request_sub_type', 'application_errors');
g_form.removeOption('request_sub_type', 'resource_allocation');
g_form.removeOption('request_sub_type', 'hardware_provisioning');
g_form.removeOption('request_sub_type', 'resource_allocation');
g_form.removeOption('request_sub_type', 'hardware_provisioning');
g_form.removeOption('request_sub_type', 'resource_allocation');
g_form.removeOption('request_sub_type', 'performance_monitoring');
g_form.removeOption('request_sub_type', 'capacity_planning');
g_form.removeOption('request_sub_type', 'scalability_requests');
g_form.removeOption('request_sub_type', 'hardware_provisioning');
g_form.removeOption('request_sub_type', 'hardware_provisioning');
g_form.removeOption('request_sub_type', 'access_management');
g_form.removeOption('request_sub_type', 'software_installation');
g_form.removeOption('request_sub_type', 'network_requests');
g_form.removeOption('request_sub_type', 'information_request');
g_form.removeOption('request_sub_type', 'onboarding');
g_form.removeOption('request_sub_type', 'vulnerability_management');
g_form.removeOption('request_sub_type', 'compliance_request');
g_form.removeOption('request_sub_type', 'configuration_changes');
g_form.removeOption('request_sub_type', 'deployments');
g_form.removeOption('request_sub_type', 'schedule_maintenance');
}
//Type appropriate comment here, and begin script below
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 08:12 AM
Oh dear! Right off the bat, there's a "g_form." line that is not complete after your first if statement. That needs to be removed.
I don't know how many items are in this list, but a cleaner approach would be to wipe out all selections (like it looks like you started to do) and then just add the ones that are needed for each condition. You don't know if a person is switching from one request type to another, and some of those remove statements will end up erroring out if they don't exist.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 08:04 AM
Similar to incident category and subcategory you can have variables with dependency in catalog
this link has solution
ServiceNow – Dependent Variables on Record Producer in Service Catalog
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-28-2025 08:09 AM
I believe that solution will only work if these are values that are pulled from a table. This appears to not be the case here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 09:37 PM
I don't have the options in a table.
also,
whenever i am changing the request type the sub request type values are getting cleared from the second time onwards. any idea how can i fix this?