I

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

Function/MethodDescriptionUsage
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.

Parameters:
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.

Parameters:
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.
g_form.hideAllFieldMsgs();
flash(widgetName, color, count)Flashes the specified color the specified number of times in the field.

Parameters:
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

Function/MethodDescriptionUsage
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
gs.addInfoMessage(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
gs.flushMessages();

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: