How can we hide a specific Subcategory option from the Subcategory choice list on the Incident form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5 hours ago
We have a business requirement on the Incident form to hide one specific Subcategory option when the Category is set to Application. Both fields (Category and Subcategory) are standard choice fields on the Incident table.
We cannot deactivate this Subcategory choice at the dictionary level because:
- The same Subcategory is still needed and actively used in other forms and processes, and
- We are creating a new Catalog Item where this Subcategory must remain visible under the Application category by default.
Because of this, the Subcategory must remain active, but it should be hidden only on the Incident form when Category = Application. All other Subcategory choices must remain available.
Can anyone advise on the best approach to achieve this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5 hours ago
We can create a new Client Script and use the g_form.removeOption() function to fulfill your requirement. Please refer to the following article for detailed guidance:
https://servicenowguru.com/client-scripts-scripting/removing-disabling-choice-list-options/
If this response was helpful, please consider marking it as Correct and Helpful. You may mark more than one reply as an accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
Hi @Ria ,
Create a OnChange Client script ( UI Type :All), and based on specific category ,using removeOption()
g_form.removeOption('field name', 'choice value');
Sample code :
- Navigate to System Definition > Client Scripts.
- Click New.
- Fill in the form:
- Name: Hide Subcategory for App
- Table: Incident
- UI Type: All
- Type: onChange
- Field name: Category
- Active: Checked
- code
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
if (newValue === 'application') { // Replace 'application' with your actual backend value g_form.removeOption('subcategory', 'specific_option'); // Replace 'specific_option' with your actual subcategory value } else {
g_form.addOption('subcategory', 'specific_option', 'Specific Option Label'); //Re-add the option if the user changes the category back
}
}- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago - last edited 3 hours ago
Hi @Ria ,
g_forms.addOption method in ServiceNow is used to dynamically add options to a dropdown.
e.g dropdown is already having options/choices (or not having).
Using addOption - you can add that new option to dropdown's existing options list ..
shared code was sample code, customize that as per your requirement and test it.
👍
