- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2016 09:01 AM
Is there a script that can be place to remove options under a variable. UI Policy will just hide the variable and that's not what I want.
For example:
If Remove User Access is selected for Type:
I want only N/A to show and not the other 2 options for Ready Only or Write.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2016 10:39 AM
Here you go
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue== 'Remove User Access') {
g_form.removeOption('edit_or_read_only', 'Read Only');
g_form.removeOption('edit_or_read_only', 'Write');
}
else{
if(g_form.getOption('edit_or_read_only','Read Only')==null){
g_form.addOption('edit_or_read_only','Read Only','Read Only');
}
if(g_form.getOption('edit_or_read_only','Write')==null){
g_form.addOption('edit_or_read_only','Write','Write');
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2017 06:29 AM
HI Wesley,
I haven't tried the g_form.removeOption() when using a reference field in "choice mode". Not sure if that will work. It's an interesting experiment. Adding the options back in... even better. I would start by using the same format of g_form.addOption() with the display value, the sys_id (as the value), and order. Again, not sure if any of it is supported in this scenario, but it can't hurt to do a quick little test.
Let me know what you find.
Reference:GlideForm (g form) - ServiceNow Wiki
Client Scripts - ServiceNow Wiki

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2016 09:39 AM
Hi johnvo
After removing the options you need to add them back if you select a different type. Here is your complete onChange client script on "Type" variable
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue== 'Choice value of Remove User Access') {
g_form.removeOption('variable name of read only or write', 'choice value of Read only');
g_form.removeOption('variable name of read only or write', 'choice valeu of Write');
}
else{
if(g_form.getOption('variable name of read only or write','choice value of Read only')==null){
g_form.addOption('variable name of read only or write','choice value of read only','choice label of read only');
}
if(g_form.getOption('variable name of read only or write','choice value of write')==null){
g_form.addOption('variable name of read only or write','choice value of write','choice label of write');
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2016 09:49 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2016 09:53 AM
Do not copy the code as is. You need to replace the variable names choice values and choice labels as highlighted below
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue== 'Choice value of Remove User Access') {
g_form.removeOption('variable name of read only or write', 'choice value of Read only');
g_form.removeOption('variable name of read only or write', 'choice valeu of Write');
}
else{
if(g_form.getOption('variable name of read only or write','choice value of Read only')==null){
g_form.addOption('variable name of read only or write','choice value of read only','choice label of read only');
}
if(g_form.getOption('variable name of read only or write','choice value of write')==null){
g_form.addOption('variable name of read only or write','choice value of write','choice label of write');
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2016 10:03 AM