clear the variable value field servicenow

Using the ‘Clear the Variable Value’ field

In recent updates, ServiceNow introduced a helpful feature within the UI Policy Action form, known as the “Clear the Variable Value” field – the topic of today’s discussion. However, developers should understand the nuances of its functionality to ensure the results are as expected.

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.

Understanding the nuances of the “Clear the Variable Value” checkbox in ServiceNow UI Policies is helpful for effective form management. By carefully considering the conditions under which this feature operates, you can avoid unintended consequences without resorting to additional client scripts. This handy feature, when used correctly, can greatly enhance the efficiency of your ServiceNow processes, making it a valuable tool to have in your development arsenal.

While the above technical tip has been provided with care and consideration, it’s important to acknowledge that individual circumstances may vary. Always ensure compatibility and feasibility within your specific ServiceNow environment before implementing any suggestions. Additionally, back up your data and proceed with caution when making any changes to your instance or workflows. 

As with any change in ServiceNow, make sure you test any changes prior to moving to production.