What It Does

The clearValue() method removes all data from the specified field on the current form. For most field types, this simply sets the field to an empty string or null value. For reference fields, the behavior is more comprehensive—it clears both the displayed text (like a user's name) and the underlying sys_id that represents the actual database relationship.

Internally, ServiceNow updates the form's field object to remove the current value, then refreshes the visual representation of that field in the browser. The field becomes truly empty—not just visually cleared but programmatically empty when checked with getValue() or similar methods. This makes it different from simply setting a field to an empty string, which might leave residual data structures intact.

The method returns void—it performs its action but doesn't provide feedback about success or failure. If you pass an invalid field name, the method fails silently without throwing an error. This silent failure can make debugging difficult when you've mistyped a field name or are working on the wrong form context.

One critical edge case involves mandatory fields. Clearing a mandatory field will trigger validation errors when the user attempts to save the form, but the clearValue() method itself doesn't prevent the clearing operation. The field becomes empty immediately, and validation only occurs during form submission. This can create a poor user experience if not handled thoughtfully.

The method works alongside other GlideForm field manipulation methods like setValue() and getValue(). Unlike setValue('', '') which requires you to know the exact format needed for each field type, clearValue() handles the complexity of properly emptying any field type with a single method call.

When to Use This

Use clearValue() when you need to programmatically empty a field based on user actions or business logic. Common scenarios include clearing dependent fields when a parent selection changes (like clearing 'Assignment Group' when 'Category' changes), resetting form sections when a checkbox is unchecked, or implementing conditional field clearing in onChange client scripts. The method is particularly valuable for reference fields where you need to ensure both the display value and the underlying relationship are completely removed.

Avoid using clearValue() when you need to set a field to a specific value—use setValue() instead. Don't use it in situations where you need confirmation that the operation succeeded, since it provides no return value. For server-side field clearing, use GlideRecord's field assignment with empty values rather than trying to call this client-side method. When working with fields that have complex validation or dependencies, consider using hideFieldMsg() to clear any error messages that might persist after clearing the value.

A common misuse pattern involves trying to clear multiple related fields without considering the order of operations. Clearing a field might trigger other onChange scripts that repopulate fields you've already cleared, creating an inconsistent form state. Always clear fields in the correct dependency order, typically from parent to child relationships.

Return Value

The method returns void (undefined in JavaScript), meaning it provides no information about whether the operation succeeded or failed. This is consistent with most GlideForm manipulation methods that focus on performing actions rather than reporting results. The absence of a return value means you cannot chain this method or use its result in conditional statements.

When the method encounters an invalid field name, it fails silently without throwing an exception or returning an error code. This silent failure means you should verify your field names are correct during development and testing. To confirm that a field was actually cleared, use getValue() immediately after clearValue() to check that the field is indeed empty.

Free Newsletter

Enjoying this? Get one deep-dive per week.

Join 1,000+ ServiceNow pros — scripts, GlideRecord patterns, Flow Designer techniques, and career moves. Free.

No spam · Unsubscribe anytime

Platform Behavior & Side Effects

  • Does not trigger onChange client scripts for the cleared field—the field is simply emptied without firing change events
  • No immediate database write occurs—the field is only cleared in the browser until the form is saved
  • Very fast operation since it only manipulates the client-side form object without server communication
  • UI Policies and Data Policies continue to evaluate normally and may override the cleared value if conditions are met
  • Clears any field-level error messages or validation indicators that were previously displayed
  • For choice fields, removes the selected option and returns the field to its default unselected state
  • Reference field clearing removes both the sys_id and display value, fully breaking the relationship until form save