Hide options in a variable

John Vo1
Tera Guru

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:

find_real_file.png

I want only N/A to show and not the other 2 options for Ready Only or Write.

find_real_file.png

1 ACCEPTED SOLUTION

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');


  }


  }



}


View solution in original post

25 REPLIES 25

Chuck Tomasi
Tera Patron

Using a catalog client script, you can use the g_form.removeOption() method to show/hide your variables. In a catalog client script, the variables operate similar to fields on a standard form/table/record.



http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)


Chuck,



Can you give me an example of how the script would look like?



Thanks,


John


it would go something like this. Update variable names and values accordingly. This is all untested on my end.



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


  if (newValue === '') {


      return;


  }



          if (g_form.getValue('type') == 'Remove User Access')) {


                  g_form.removeOption('additional_information', 'Read only');


                    g_form.removeOption('additional_information', 'Write');


        }


}


Would this be a catalog client script under the catalog item?