Client Script to remove choice list option
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2011 07:53 PM
I'm trying to remove a field option from a choice list using a client script with g_form.removeOption. I don't want anyone that doesn't have the "ewr_manager" role to have the option to closed a task. I'm using the script below that I found on the wiki, but I'm getting some unexpected results.
Should Closed (value of 😎 be visible to the user if the current status of the task is 8 and they do not have the ewr_manager role? I don't want closed to display if the task is in some other status, but I do want it to be visible if the status is currently Closed.
http://wiki.service-now.com/index.php?title=GlideForm_%28g_form%29#Change_Choice_List_Methods
function onLoad() {
var isEwr = g_user.hasRole('ewr_manager');
var ewrStatus = g_form.getValue('u_status');
//alert('EWR status ' + ewrStatus);
//alert('role ' + isEwr);
if (!isEwr && (u_status != 8)){
g_form.removeOption('u_status', '8');
}
}
Thanks for any help.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2011 04:52 AM
You should only remove the option if it is not the currently-selected option when the form loads. This article has some examples that show you how to do that.
http://www.servicenowguru.com/scripting/client-scripts-scripting/removing-disabling-choice-list-options/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2011 08:17 AM
Mark
Thanks for the info. It might have been something with our test instance. I was able to get the script to work in Dev.
Rick