What It Does
The hideFieldMsg() method removes informational, warning, or error messages that have been displayed beneath form fields. These messages are typically added by showFieldMsg() calls in client scripts, UI policies, or through server-side validation that surfaces on the client. The method operates entirely within the browser's DOM and doesn't communicate with the server.
ServiceNow maintains a message queue for each form field, allowing multiple messages to stack beneath a single field. When clearAll is false (the default), the platform removes only the most recently added message from the queue. When clearAll is true, the entire message queue for that field is cleared, removing all visible messages at once.
The method returns void and provides no indication of success or failure. If you specify a field name that doesn't exist on the current form, the method fails silently without throwing an error or logging a warning. This behavior is consistent with other GlideForm methods that operate on form fields.
An important edge case occurs with reference fields and their dependent fields. If you hide messages on a reference field that has dependent fields (like location → company), the dependent field messages remain visible even if they're logically related to the parent field's validation state. You must explicitly call hideFieldMsg() for each dependent field that needs its messages cleared.
This method works in conjunction with showFieldMsg() and clearMessages() to provide complete control over field-level messaging. Unlike clearMessages() which removes all messages from all fields on the form, hideFieldMsg() provides surgical precision for individual field message management.
When to Use This
Use hideFieldMsg() when you need to clear field-specific validation messages or informational text in response to user actions. Common scenarios include clearing error messages after a user corrects invalid input, removing conditional help text when certain selections change, or hiding temporary status messages after an async operation completes. This method is essential for creating responsive, user-friendly forms that provide immediate feedback.
Don't use this method when you need to clear messages from multiple fields simultaneously—use clearMessages() instead. Also avoid using it to hide form-wide notification messages that appear at the top of the form; those require clearMessages() or direct DOM manipulation. A common misuse pattern is calling this method repeatedly in onChange events without checking if messages actually exist, which creates unnecessary DOM operations.
Timing matters significantly with this method. Calling hideFieldMsg() immediately after showFieldMsg() in the same script execution can create race conditions where messages flicker or don't appear at all. When building complex validation flows, structure your logic to avoid immediately hiding messages you just displayed.
Return Value
The method returns void (undefined) in all cases. There's no return value to indicate success, failure, or whether any messages were actually removed. This design choice aligns with other GlideForm methods that perform UI operations rather than data retrieval. The method completes synchronously, so any code following the call will execute after the message hiding is complete.
Since there's no return value to check, you cannot programmatically determine if the operation succeeded. If you need to verify that messages were cleared, you'll need to implement your own tracking mechanism or use DOM inspection methods to check the current state of field messages after the call completes.
Enjoying this? Get one deep-dive per week.
Join 1,000+ ServiceNow pros — scripts, GlideRecord patterns, Flow Designer techniques, and career moves. Free.
Platform Behavior & Side Effects
- Operates entirely on the client-side DOM without triggering any server communication or database operations
- Does not fire Business Rules, ACLs, notifications, or any other server-side platform mechanisms
- Executes synchronously with minimal performance impact—simply removes DOM elements from the message queue
- Cannot be used in Before or After Business Rules since it requires the client-side form context
- Works identically in UI Policies and Client Scripts, but UI Policy execution timing may affect message visibility
- Messages cleared by this method are permanently removed from the client session—they won't reappear unless explicitly re-added
- Form submission will proceed normally even if validation messages were hidden—clearing display messages doesn't affect underlying validation logic