The CreatorCon Call for Content is officially open! Get started here.

janiceg
ServiceNow Employee
ServiceNow Employee

Sometimes you might want to hide a Service Catalog variable, for example, based on the customer's geographic location or on the item ordered. (You might, for example, want to hide the "cpu_speed" variable if customers order an Executive Desktop.) Using a Service Catalog UI policy to hide a task variable does not work as well as one might hope: the variable is hidden in some places but not others. Hide-and-seek with task variables has been a game enjoyed played between task variables and users on certain patches of Eureka.

When do Catalog task variables appear/disappear?

hide.jpg
  • Using the catalog client script, g_form.setDisplay works on the catalog item but does not hide the variable on the task
  • Similarly, using a catalog UI policy works on the catalog item but it does not hide the variable on the task
  • Using g_form.setVisible does not hide the variable on the catalog item or task

Workaround for disappearing catalog task variables

To work around this issue, create an onLoad catalog client script that does both setVisible and setDisplay.

  1. Navigate to Service Catalog > Catalog Client Scripts.

  2. Click New.

  3. Set Type to onLoad.

  4. Set Applies to Requested Items to true.

  5. Set Applies to Catalog Task to true.

  6. Within the function onLoad() in the script field, add the following two lines:

    g_form.setVisible('variables.macro_name', false);

    g_form.setDisplay('variable_sys_id', false);

    where variable_sys_id is the sys_id of the variable of type 'Macro'

    onload-function.png

The variables should now remain hidden in all desired locations.

Related information

2 Comments