What It Does

The showFieldMsg() method renders a message directly below a specific field on the current form. The message appears in the field's container area, visually connecting the feedback to the relevant input. ServiceNow injects a small div element immediately after the field's input wrapper with appropriate CSS classes for styling.

The platform maintains an internal registry of field messages per form session. When you call this method, ServiceNow updates this registry and immediately renders the visual change without requiring a form refresh. Multiple messages can exist simultaneously on different fields, but only one message per field - subsequent calls to the same field replace the previous message.

The method returns void and executes synchronously. If the specified field doesn't exist on the current form, the method fails silently - no error is thrown and no message appears. This differs from addInfoMessage() which always displays at the form header level.

Field messages persist through client-side form changes but disappear on form submission or page refresh. They don't trigger any server-side events or business rules since they're purely cosmetic UI elements. The messages are not accessible via screen readers by default, so consider this for accessibility requirements.

Related methods include clearMessages() which removes all field messages, and hideFieldMsg() which removes messages from specific fields. The global message methods addInfoMessage() and addErrorMessage() work at the form level rather than field level.

When to Use This

Use showFieldMsg() for field-specific validation feedback, format requirements, or contextual help that relates directly to a single field. Perfect for real-time validation in onChange client scripts, showing password requirements under password fields, or displaying calculation results next to computed fields. The proximity to the relevant field makes the user experience much clearer than header-level messages.

Don't use this for form-wide messages, submission confirmations, or anything requiring the user's immediate attention across the entire form. Use addErrorMessage() or addInfoMessage() instead. Avoid showing critical error messages that prevent form submission only at the field level - users might miss them. Also avoid this method for fields that aren't currently visible, as the message won't appear until the field becomes visible.

Common misuse includes trying to show multiple messages per field (only the last one displays), using it for debugging information that should go to the console, or expecting the messages to persist across form submissions. Remember that users scrolling quickly through long forms might miss field-level messages entirely.

Return Value

Returns void (undefined) in all cases. The method provides no feedback about whether the field exists, whether the message was successfully displayed, or whether the type parameter was valid. Success or failure must be determined by visual inspection of the form or by checking if the field exists beforehand using g_form.isVisible() or similar methods.

Since there's no return value to check, wrap calls in conditional logic if you need to verify field existence first. The method executes immediately and synchronously, so any visual changes appear right away if the field exists and is currently rendered on the form.

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 client-side DOM manipulation with no database interaction
  • Messages are not logged, audited, or stored anywhere - they exist only in the current browser session
  • Performance impact is minimal - direct DOM manipulation without AJAX calls or server round-trips
  • Messages automatically clear when the form is submitted, refreshed, or navigated away from
  • Works identically in Client Scripts, UI Policies, and UI Actions - no behavioral differences between contexts
  • Messages persist through section expand/collapse and tab switching but disappear if the field is hidden via UI Policy
  • CSS classes applied are 'notification notification-info' for info type and 'notification notification-error' for error type