Hide Options from Select Box
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2018 07:34 AM
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.
- Labels:
-
Incident Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2018 12:47 PM
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?
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2018 06:58 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2018 08:23 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2018 08:35 AM
I just noticed that 'applies on catalog item view' is not selected - I think this is why nothing has worked so far!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2018 10:55 AM
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
Step 2: To verify variable name go the variable category and check name field