Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

How can we hide a specific Subcategory option from the Subcategory choice list on the Incident form

Ria
Tera Contributor

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?

11 REPLIES 11

lochuynh33
Tera Guru

 

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

 

Tanushree Maiti
Tera Sage

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 :

  1. Navigate to System Definition > Client Scripts.
  2. Click New.
  3. Fill in the form:
    • Name: Hide Subcategory for App
    • Table: Incident
    • UI Type: All
    • Type: onChange
    • Field name: Category
    • Active: Checked
  4. 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
    }
}
 
 
Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

Hi @Tanushree Maiti 

We cannot use g_form.addOption because there are too many records.

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.

👍

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: