Remove option from lookup select box for non-Admins

Jason Stephens
Kilo Guru

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
   }
}

1 ACCEPTED SOLUTION

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.

View solution in original post

4 REPLIES 4

asifnoor
Kilo Patron

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.

 

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!!

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.

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!