Hide Options from Select Box

jessicaa_perry
Kilo Contributor

For the Create Incident form, I added Category as an option.  I was able to add this option and it inserts into the Incident table.  Success!

However, I only want a few categories available for our users to choose from in this form.  We'll call these internal vs. external categories.  How do I hide the internal categories?

After some research, I'm trying to use the onLoad function with the g_form.removeOption, but I can't seem to get it to work.  This is my first time working with client scripts.

15 REPLIES 15

okay, so here in the previous script we are trying to check if Category value is backuptapes then remove the value but i believe on load there is no value in Category so that's why it will not go inside if condition. Can we try with below code, let's see if this helps.

 

function onLoad() {
if (!g_user.hasRole('itil_admin'))
g_form.removeOption('Category', 'backuptapes'); //Please verify if the variable name is Category or category? 
}

jessicaa_perry
Kilo Contributor

That code didn't work either.  The variable name is Category.  It seems like this should work, but Backup Tapes still shows up.

I'm not sure if it will help since this current code isn't working, but maybe I should come at this from a different angle.  Instead of hiding options, maybe I use g_form.setValue to show the categories I want users to see.

Not sure if it will help or not, but the example on https://www.servicenowguru.com/ declares the g_user and g_form references as a variable first. Could you try this and see what happens?

function onLoad() {
var isItilAdmin = g_user.hasRole('itil_admin');

if (!isItilAdmin ){
g_form.removeOption('Category', 'backuptapes');
}
}

 

Matt

 

I just noticed that 'applies on catalog item view' is not selected - I think this is why nothing has worked so far!

slesha1
Giga Contributor

g_form.removeOption('Category', 'backuptapes'); works for me.

Can you verify and see if the variable name and option name matches with 'Category' and 'backuptapes'

Step 1. To verify option name, go to incident and right click on the category label to open its dictionary. Look for 'backuptapes' choice in the related list. Copy its value 

find_real_file.png

Step 2: To verify variable name go the variable category  and check name field

find_real_file.png