What It Does

The clearMessages() method removes all notification messages currently displayed in the form's message area. This includes both informational messages (blue) and error messages (red) that appear at the top of the form, typically below the form header but above the field sections.

Internally, ServiceNow maintains a client-side message queue for each form instance. When you call clearMessages(), the platform empties this queue and removes the corresponding DOM elements from the form's message container. The method operates synchronously and completes immediately.

This method returns void and never fails or throws exceptions. It safely handles cases where no messages exist, simply performing no operation. The method only affects messages added through g_form.addInfoMessage() or g_form.addErrorMessage() — it cannot remove system-generated validation messages or server-side notifications.

The method only clears messages from the current form instance and does not affect messages on other forms or browser tabs. Messages cleared by this method are permanently removed from the client-side queue and cannot be restored without re-adding them explicitly.

This method works alongside other GlideForm messaging methods: addInfoMessage() and addErrorMessage() add messages, while clearMessages() removes them all at once. There is no method to remove individual messages by content or ID.

When to Use This

Use clearMessages() when you need to reset the form's message state, typically in onChange client scripts that perform validation checks. Common scenarios include clearing previous validation messages before running new checks, removing outdated informational messages when field values change, or cleaning up messages before displaying new ones to avoid message buildup.

Avoid using this method if you need granular control over specific messages. Since it removes all messages indiscriminately, use addInfoMessage() or addErrorMessage() strategically instead of clearing and re-adding messages unnecessarily. Also avoid calling this method repeatedly in tight loops as it causes unnecessary DOM manipulation.

Return Value

This method returns void and provides no return value to capture or check. The method never fails or returns error conditions — it simply performs the clear operation if messages exist or does nothing if the message queue is already 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

  • No server-side communication occurs — this is purely a client-side DOM operation
  • No database writes are triggered and no audit entries are created
  • Business rules, workflows, and notifications are not triggered by this method
  • Performance is fast as it only manipulates existing DOM elements without creating new ones
  • Method works identically in all client-side contexts (Client Scripts, UI Policies, UI Actions)
  • Messages are immediately removed from the visible UI with no fade or transition effects
  • Browser accessibility tools are notified when messages are removed for screen readers