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

That was my assumption based on the fact that you posted this in the Service Catalog space on the community and were referencing variables rather than fields.


So where in this script would I put the variable Type and Read Only and Write?



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


        }


}


Your onChange client script would be set to watch the "Type" field.



That being said, this could be simplified slightly be doing this:



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


  if (newValue === '') {


      return;


  }



          if (newValue== 'Remove User Access')) {


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


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


        }


}



newValue represents the choice changing select on the Type field to be "Remove User Access". If that is true, then the next two lines remove the Read only and Write options from the Additional information choice list.


This is what i have and it didn't work.



find_real_file.png


Hi Chuck,



Just wanted to confirm if there is any impact if you use the removeOption on a 'Reference' field or 'Type' = Select Box from a Catalog or Record Producer form (Incident, Change etc.).   Will it also physically remove the option from the actual reference field of table since the field is being "reference to".   Or does it use some type of copy /cache method on the actual form itself.   Example, Category and Subcategory fields being reference from the Incident table.   If options are removed with a client script on on the entry from, will the options be removed from the Incident table Category or Subcategory field(s) as well.   Hope this makes sense?



If yes, what would be the workaround to re-add the options after the form has been submitted, so future forms will contain all the same options.   Or just don't reference a field at all if option need to removed.



Thank you,


-Wesley