How to hide options of category field on Incident form for a view

Su Tyagi
Tera Contributor

Hi all,

 

We have created a view (XYZ) and want to hide OOTB options of category field on Incident form. Basically, we have created a view for the set of people who should use thier own incident form and shouldn't have access to  OOTB process. I have hide category and subcategory options from these users.

I have created a view rule as well.

 

Thanks,

Su

1 ACCEPTED SOLUTION

Brad Warman
Giga Sage

Hi @Su Tyagi ,

 

In an onLoad client script, uncheck the global checkbox and then enter the view you want the client script to apply to.

 

BradWarman_0-1753926182237.png

 

Then you can use the removeOption method on g_form to remove the options that shouldn't be visible.

 

g_form.removeOption('category', '1');

 

https://developer.servicenow.com/dev.do#!/reference/api/yokohama/client/c_GlideFormAPI#r_GlideFormRe...

 

 

View solution in original post

4 REPLIES 4

Chaitanya ILCR
Kilo Patron

Hi @Su Tyagi ,

 

You can clear all options 

Create an onLoad client script

function onLoad() {

    // Replace 'XYZ' with the actual name of your view if it's different.
    if (g_form.getViewName() == 'XYZ') {

        // Clear all options from the 'category' field
        g_form.clearOptions('category');
        // Example of how to add a specific option back if needed:
        // g_form.addOption('category', 'your_value', 'Your Display Label');

        // Clear all options from the 'subcategory' field
        g_form.clearOptions('subcategory');
        // Example of how to add a specific option back if needed:
        // g_form.addOption('subcategory', 'your_value', 'Your Display Label');
    }
}

 

Or you can hide those fields entirely instead of hiding all options 

function onLoad() {
    
    // Replace 'XYZ' with the actual name of your view if it's different.
    if (g_form.getViewName() == 'XYZ') {

        // Hide the 'category' field
        g_form.setDisplay('category', false);

        // Hide the 'subcategory' field
        g_form.setDisplay('subcategory', false);
    }
}

 

Regards 

Chaitanya 

 

Brad Warman
Giga Sage

Hi @Su Tyagi ,

 

In an onLoad client script, uncheck the global checkbox and then enter the view you want the client script to apply to.

 

BradWarman_0-1753926182237.png

 

Then you can use the removeOption method on g_form to remove the options that shouldn't be visible.

 

g_form.removeOption('category', '1');

 

https://developer.servicenow.com/dev.do#!/reference/api/yokohama/client/c_GlideFormAPI#r_GlideFormRe...

 

 

Thanks Brad!

Worked like a charm..

Su

Ankur Bawiskar
Tera Patron
Tera Patron

@Su Tyagi 

you can use g_form.removeOption(), g_form.addOption() and manipulate the options of category field.

what did you start with and where are you stuck?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader