What It Does

The addErrorMessage() method displays a red error message at the top of the current form, immediately below the form header. The message appears with a distinctive red background and error icon, making it clearly visible to users. ServiceNow's form rendering engine adds the message to a queue that displays all error messages in the order they were added.

Internally, ServiceNow maintains an array of error messages associated with the current form session. When you call addErrorMessage(), the platform pushes your message onto this array and immediately updates the DOM to render the error banner. The message persists until the user navigates away from the form, submits successfully, or the form is refreshed.

This method returns void and always succeeds - there are no failure conditions. Even if you pass null or undefined, ServiceNow will convert these to strings and display them. The message text is escaped to prevent XSS attacks, so HTML tags display as literal text rather than being rendered.

⚠️

addErrorMessage() does NOT prevent form submission. Users can still click Save or Update even with error messages displayed. Use return false in onChange scripts or mandatory field validation for actual submission prevention.

The method works alongside other GlideForm messaging methods like addInfoMessage() and clearMessages(). Multiple error messages stack vertically in the order added, and clearMessages() removes all messages including errors. Error messages have higher visual priority than info messages due to their red styling.

When to Use This

Use addErrorMessage() for client-side validation that requires user attention but allows them to continue working on the form. Perfect for onChange field validation, complex business rule violations, or when checking related record states that should block submission. Use it in Client Scripts when you need to inform users about data quality issues or missing required information across multiple fields.

For simple field-level validation, use showFieldMsg() instead to display the error directly next to the problematic field. For server-side validation that should absolutely prevent submission, implement your logic in Business Rules rather than relying on client-side messages. Use addInfoMessage() for warnings or informational content that doesn't indicate an error condition.

Avoid using this method for every validation scenario - too many error messages overwhelm users and reduce their effectiveness. Don't use it for validation that ServiceNow's mandatory field or data policy mechanisms can handle automatically. Never rely solely on client-side error messages for security or data integrity since users can disable JavaScript or manipulate the client.

Return Value

This method returns void (undefined) and provides no indication of success or failure. The operation always succeeds from a technical perspective - even invalid inputs get converted to strings and displayed. You cannot chain this method or use its return value in conditional statements.

Since the method provides no feedback about message display, you cannot programmatically determine if the user has seen or dismissed the error. The message remains visible until the user navigates away, the form refreshes, or clearMessages() is called. Design your validation logic accordingly, assuming the message will persist for the entire form session.

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 events fire - this is purely a client-side DOM manipulation with no Business Rules, Script Includes, or notifications triggered
  • Nothing gets written to the database - error messages exist only in the browser session and are not logged or stored
  • Extremely fast execution with no network round-trips required - the message displays immediately when called
  • Messages are not cached or persisted - refreshing the form or navigating away removes all error messages permanently
  • Works identically in Client Scripts, UI Policies, and UI Actions - no behavioral differences based on execution context
  • Multiple calls stack messages vertically without replacing previous ones - each call adds to the existing message queue
  • Message text is automatically escaped for XSS protection - HTML tags display as literal text and cannot be used for formatting