UI Info and Error Message Cheat Sheet

/, System UI/UI Info and Error Message Cheat Sheet

UI Info and Error Message Cheat Sheet


nformation messages are a great way to provide UI feedback to end users as they interact with the various forms in your instance. This article describes the various methods you can use to display information messages to the users accessing your ServiceNow system.

Client-side UI Messages

The following methods are designed for use in client-side scripting (primarily client scripts and UI policies). As such, they are used on standard forms and on catalog forms and can run on load or submit of a form, or on change of a field value.

Client-side Info and Error Messages

addInfoMessage(message)Displays an informational message at the top of the form with a blue information icon and a light-blue background.g_form.addInfoMessage('Form Info Message Text');
addErrorMessage(message)Displays an error message at the top of the form with a red error icon and a light-red background.g_form.addErrorMessage('Form Error Message Text');
clearOutputMessagesHides ALL form info and error messages. There is no way to remove form info and error messages individually.GlideUI.get().clearOutputMessages();
showFieldMsg(input, message, type, [scrollForm])Displays either an informational or error message under the specified form field (either a control object or the name of the field). Type may be either "info" or "error." If the control or field is currently scrolled off the screen, it will be scrolled to.

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

Optional: Set scrollForm to false to prevent scrolling to the field message offscreen.

input - specifies the name of the field or control.
message - the message to be displayed.
type - error or info.
scrollForm (optional) - true to scroll to message if offscreen, false to prevent this scrolling.
//Field info message
g_form.showFieldMsg('priority','Priority is low.','info');

//Field error message
g_form.showFieldMsg('impact','Priority is high!','error');
hideFieldMsg(input, [clearAll])Hides info and error messages for a single field.

input - specifies the name of the field.
clearAll (optional) - boolean parameter indicating whether to clear all messages. If true, all messages for the field will be cleared; if false or empty, only the last message will be removed.
g_form.hideFieldMsg('impact', true);
hideAllFieldMsgs([type])Hides all field info and error messages.

Optional: Provide type to hide only "info" or "error" messages.
flash(widgetName, color, count)Flashes the specified color the specified number of times in the field.

widgetName - Specifies the element with (table name).(fieldname).
color - RGB or CSS color
count - How long the label will flash.
use 2 for a 1-second flash
use 0 for a 2-second flash
use -2 for a 3-second flash
use -4 for a 4-second flash
g_form.flash("incident.number", "#CC0000", -2);

Server-side UI Messages

Although messages will always be displayed client-side, they are often initiated from a server-side script like a business rule, record producer script, or script include. Messages initiated from server-side scripts can appear at the top of any form or list and are typically triggered by a database action such as a record insert, update, or delete.

Server-side Info Messages

addInfoMessage(message)Displays an informational message for the current session with a blue information icon and a light-blue background.

Can also include HTML in the message! Note that I've replaced the greater than and less than symbols with brackets in the HTML usage example to get it to display correctly here. You'll need to change the brackets back to standard HTML to get it to work in your instance.
gs.addInfoMessage('Session Info Message Text');

//Info message with HTML formatting
//Create the html contents of the information message
var link = '[a href="incident.do?sys_id=' + current.sys_id + '" class="breadcrumb" ]' + current.number + '[/a]';
var message = 'Incident ' + link + ' has been created. ';
message += 'Thank you for your submission.';

//Add the information message
addErrorMessage(message)Displays an error message for the current session with a red error icon and a light-red background.

Can also include HTML in the message!
gs.addErrorMessage('Session Error Message Text');
flushMessages()Clears any existing session info or error messages to prevent them from being displayed.//Clear any session info or error messages

UI Notifications

UI Notifications are an unusual class that can be used for refreshing elements such as the navigation pane or for displaying messages in response to changes in database tables. For more information about UI Notifications, check out the following articles:

By | 2018-07-09T14:59:53-06:00 October 10th, 2012|Categories: Scripting, System UI|Tags: , , , , |18 Comments

About the Author:


  1. Justin March 25, 2013 at 4:18 pm - Reply

    Is there a way to detect if a field message is displaying or not?

    It would be nice if there was a way to detect if there is a field message displayed on the page without searching document for a div with class=”outputmsg_error” or class=”outputmsg_warning”.

    • Mark Stanger March 25, 2013 at 4:27 pm - Reply

      Hey Justin, unfortunately, there isn’t. Too bad there aren’t any good element IDs provided in this case.

  2. Amisha Parekh April 4, 2013 at 10:28 pm - Reply

    Is there is any way to change color of Error Message at client side?

    • Mark Stanger April 5, 2013 at 7:05 am - Reply

      No simple way to change the background color, but you can change the text color by adding HTML to the message as shown in the example above.

  3. John March 26, 2014 at 9:21 am - Reply

    Is there a table or doc anywhere that has all the possible Error and Warning messages listed?. It would be nice to be able to suppress the messages you don’t want or need to see.

    • Mark Stanger March 26, 2014 at 9:50 am - Reply

      Anything like that would need to be provided by ServiceNow, but I don’t think that will happen. There are very few messages that appear in the product that aren’t part of standard client scripts, business rules, or UI actions. All you need to do in most cases is examine the code in those places to determine where the error message originates from.

  4. Chris Royer May 21, 2014 at 3:10 pm - Reply

    Is there a way to flash a catalog item field?

    • Chris Royer May 21, 2014 at 3:30 pm - Reply

      I answered my own question
      ^^^^So that’s my widgetname for catalog variables.

  5. How we can remove or hide the server UI messages? September 8, 2014 at 8:29 am - Reply

    How we can remove or hide the server UI messages?

    • Mark Stanger September 8, 2014 at 1:49 pm - Reply

      Clearing messages (server-side or client-side) is accomplished via the ‘GlideUI.get().clearOutputMessages();’ call shown above in the client-side section.

  6. William Smith February 18, 2016 at 7:23 am - Reply

    Hi Mark, it appears some of the CSS coding changed in Geneva. I am getting an error when attemping to apply CSS to the info message in your example. Could you tell me what the updated code would be for: g_form.addErrorMessage(‘[b]Form Error Message Text (Bold)[/b]’); ?

    I have a note for a different CSS styling that I found, which may help with the styling…

    Set field width:

    Fuji: https://www.servicenowguru.com/system-ui/field-styles-service-catalog-variables/
    g_form.getControl(‘VARIABLE_NAME’).style.width = ‘150px’;

    Geneva: https://community.servicenow.com/message/881984#881984

    • Mark Stanger February 18, 2016 at 11:31 am - Reply

      Looks like the support for this in client-side messages has been removed in the Geneva release. You can’t inject your own html anymore using the basic methods unfortunately. I’ve updated the documentation above to reflect this. If you’d like to see the behavior in Geneva you’ll need to contact ServiceNow support to see about an enhancement.

  7. John January 20, 2017 at 5:54 pm - Reply

    Mark, is there a simple way to make the showFieldMsg() messages permanent? All of mine go away after the field they’re attached to is changed.

    For example, if I add one to an email address field then you type something in that field and blur it, the message goes away. I want it to stay there permanently.

    • Mark Stanger January 20, 2017 at 7:38 pm - Reply

      The only ways to do this are to set up the field message in an ‘onChange’ script so that it’s evaluated each time the field changes (and re-displays accordingly) or to avoid field messages entirely and just use an annotation if the message is always supposed to be there.

  8. Christopher Jordan February 1, 2017 at 1:04 pm - Reply

    Is there a way to extend the addInfoMessage duration? I was hoping it would take an additional parameter like the number of ms or seconds to keep it up without requiring interaction.

    • Mark Stanger February 2, 2017 at 6:36 am - Reply

      None that I’m aware of, but I haven’t had any opportunity to dig into the API. You might get another opinion on the SN community.

  9. Subramani Kumarasamy February 3, 2017 at 5:43 am - Reply

    How to disable the close option in addInfoMessage. If we use addInfoMessage(“Hi How are you”). It will be displayed at the top of the form and user has an option to close this message.

    My requirement is like to make the Message permanently at the top of the form.
    Please anyone help me to achieve this.

    • Mark Stanger February 6, 2017 at 8:59 am - Reply

      This might change depending on what version of ServiceNow you’re running, but on the Helsinki version I’ve got as a sandbox you can use an ‘OnLoad’ client script with the following code to hide the close button in the info message container.


Leave A Comment