Display field messages

reference brazil Updated Sep 10, 2026 1 min read r_DisplayFieldMessages.md
Raw file servicenow.com

Rather than use JavaScript alert(), for a cleaner look, you can display an error on the form itself. The methods showFieldMsg() and hideFieldMsg() can be used to display a message just below the field itself.

showFieldMsg and hideFieldMsg are methods that can be used with the g_form object.

These methods are used to change the form view of records (Incident, Problem, and Change forms). These methods may also be available in other client scripts, but must be tested to determine whether they work as expected.

When a field message is displayed on a form on load, the form scrolls to ensure that the field message is visible. Ensuring that users do not miss a field message because it was off the screen.

The global property glide.ui.scroll_to_message_field controls automatic message scrolling when the form field is offscreen (scrolls the form to the control or field).

Method Detail

Parameters

Example

showFieldMsg(input, message, type, [scrollform])

  • input — name of the field or control
  • message — message you would like to appear
  • type — 'info', 'error', or 'warning'; defaults to info if not supplied
  • scroll form — (optional) Set scrollForm to false to prevent scrolling to the field message offscreen

Error message```javascript g_form.showFieldMsg('impact','Low impact not allowed with High priority','error');

JavaScript
\[Omitted image "ShowFieldMsgError.png"\] Alt text: Low impact not allowed with high priority message.
Informational message
```javascriptg_form.showFieldMsg('impact', 'Low impact response time can be one week','info');//or this defaults to info type//g_form.showFieldMsg('impact', 'Low impact response time can be one week');

[Omitted image "ShowFieldMsgInfo.png"] Alt text: Low impact response time can be one week message.

hideFieldMsg(input)

  • input — name of the field or control
  • clearAll — (optional) boolean parameter indicating whether to clear all messages. If true, all messages for the field are cleared. If false or empty, only the first message is removed

Removing a message```javascript //this will clear the first message printed to the field g_form.hideFieldMsg('impact');

Text
</td></tr></tbody></table>## Legacy support
The showErrorBox\(\) and hideErrorBox\(\) methods are not recommended.
**Parent Topic:**[Writing client-side scripts](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/brazil/markdown/api-reference/scripts/client-side-scripting-overview.md)
Search documentation
Search document titles and file paths on the brazil branch