- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2016 07:35 PM
Hello Community,
I am trying to hide this item in the drop down list (its value is 3):
I tried to follow these links but they did not work for me:
Server-side script to hide values in incident state dropdown
How does one filter a field of type "workflow" based on the role of the logged in user?
I tried applying the code in the above forums here but it still appears.
- answer = true;
- // If has role and the choice is closed (value = 3)
- if (gs.hasRole('role here') && current.value == 3 && current.name == 'change_request' && current.element == 'state') {
- answer = false;
- }
When I tried flipping the code, it ended up hiding the entire "State" variable from the table which was not desired.
answer = false;
// If has role and the choice is closed (value = 3)
if (gs.hasRole('change_request_admin') && current.value == 3 && current.name == 'change_request' && current.element == 'state') {
answer = true;
}
Again, I only want to hide the "Closed Complete", from the "State" drop down list.
Any help would greatly be appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2016 06:53 PM
Hello Community,
I was able to get the piece of code working.
Here is the code that I used
function onChange() {
//Type appropriate comment here, and begin script below
var isCSAdmin = g_user.hasRole('change_request_admin');
var changestate = g_form.getValue('state');
if (!isCSAdmin){
g_form.removeOption('state', '3', 'Close Complete');
}
else{
if (isCSAdmin = true){
}
}
}
SS of procedure:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2016 07:42 PM
Check out the client script "g_form.removeOption".
if (g_form.getValue('state') == '6'){
var isAdmin = g_user.hasRole('admin');
if (!isAdmin){
g_form.removeOption('state', '-1');
g_form.removeOption('state', '-2');
}
}
Reference: What are some of the available helper functions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2016 07:43 PM
Hello Jarod,
Let me give it a try and report back.
Thanks for your prompt reply.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2016 07:52 PM
I tried out your code listed below with changes to meet my instance:
if (g_form.getValue('state') == '3'){
var iscradmin = g_user.hasRole('change_request_admin');
if (!iscradmin){
g_form.removeOption('state', '12');
//g_form.removeOption('state', '-2');
}
}
For some reason this code is hiding the entire "State" variable.
Is there something I am doing wrong?
I have tried substituting "state" for "Closed Complete" and changed the numbers from 3, 12, -3, -12.
I included this SS of the dictionary of drop down items:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2016 09:19 PM
Give a try with clearOption() and then addOption()
clearOptions(fieldName);
http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#addOption