Recent versions of ServiceNow have featured a checkbox field on the UI Policy Action form (for both Catalog UI Policies and standard UI Policies) labeled “Clear the variable value” (or “Clear the field value” on standard UI policies). The use of this checkbox is straightforward: It clears the value held by the associated variable/field when the UI Policy evaluates to true.
However, care must be taken when determining what the “true” condition for the UI Policy should be or you may encounter initially unexpected behavior.
For example, say you were to create a field on the Incident table called “No CI Affected” to make users directly acknowledge that a CI is not relevant to the incident they are creating. When this box is checked, you want the Configuration Item field to be hidden and, when it is hidden, you want the Configuration Item field to be cleared of its value. Likewise, when the box is unchecked, you want the field to be visible and mandatory. You may set up the UI Policy as shown below:
This configuration may appear to work. The field will hide/show appropriately when the checkbox is checked/unchecked, and simply putting in a value and checking/unchecking the box to test clearing the value will work as well. However, and issue would be noticed, in practice, upon loading a saved incident form. If a Configuration Item value is saved, it’ll be cleared by the UI Policy on-load!
This is because the condition (No Ci Affected is false) evaluates to true when the form is loaded, clearing the value. This seems like common sense, but we often have the freedom to only consider the UI Policy condition and the true/false values on the UI Policy Actions relative to each other. The “Clear the Field/Variable” value field requires us to consider the UI Policy condition in an absolute case.
To avoid the issue in this case, we just need to flip the condition/policy action logic. The UI Policy should trigger when “No CI Affected” is true and, in that case, the Configuration Item field should be set to Mandatory: False and Visible: False. This will still give us the form behavior we expect, without additionally clearly the field on-load.
If this narrow issue case can be avoided, the “Clear the Field/Variable” checkbox is a convenient measure to avoid having to create client scripts to perform similar actions, which was necessary in earlier versions.