
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2019 09:48 AM
I am trying to remove an option from a lookup select box catalog variable (referencing the group table) if the user is not an admin. This should be fairly straightforward but I can't get it to work. It hits the conditions correctly (my alert pops up if I uncomment it), but all values have been removed from the select box, not just the specific one that I'm asking to remove. Below is my code. Any ideas? There's not a lot going on here, but I'm stumped.
//Hide the 1234 group choice in the access type field if the user is not an admin
function onLoad() {
var isAdmin = g_user.hasRole('admin');
var group = g_form.getValue('access_group');
if (!isAdmin && (group != 'a5f018a94fc3ab00a99644401310c785')){ //user is not admin and 1234 group not selected
//alert('Current user is not an admin');
g_form.removeOption('access_group','a5f018a94fc3ab00a99644401310c785');//hide 1234 group choice
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2019 10:22 PM
The reason it will not work is that your reference field basically populates from the server side on the input. Hence you cannot modify them on the client end.
Mark the comment as correct if this answers your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2019 10:35 AM
Hi,
Remove option does not remove the reference values.
Check this link for more information
https://community.servicenow.com/community?id=community_question&sys_id=d25f72a9db58dbc01dcaf3231f961989
Mark the comment as a correct answer if this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2019 12:04 PM
So it's just not possible? I don't see where that post was ever answered. I guess I can just change to a normal select box if I have to. I was just trying to avoid manual maintenance later if the groups change. Thank you for the reply btw!!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2019 10:22 PM
The reason it will not work is that your reference field basically populates from the server side on the input. Hence you cannot modify them on the client end.
Mark the comment as correct if this answers your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2019 06:47 AM
Yes, it makes sense that it doesn't. I'll just modify the field to be a select box. It's only a few groups anyway and won't be too big of a deal. Thank you for for the help!