Messages Overview

Messages can be utilized to provide translations for several different scenarios where Info, Error, and other system messages are displayed. This allows users to not have to manage the translation directly in the scripts that generate the messages and instead manage them from a central Messages[sys_ui_message] table.

These Messages are used in a number of areas in the system to display placeholder text, help text information, etc throughout the UI. I will give an example of how to change the Filter Navigator placeholder text further on in this article.

They can also be used as a time-saving mechanic when generating these system messages so that they always have the same look and feel but also contain dynamic content. I will be explaining this below.

Messages[sys_ui_messages] Table

We will first create our Messages that will be used during this example. Please note that you can utilize the Messages functionality but in order to support translations, the I18N: Internationalization plugin must be activated.

Go to the Message[sys_ui_message] table by navigating to System UI > Messages or sys_ui_message.list in the Filter Navigator. I’m showing the Message records for my two languages I’ll be working with, English and Pirate.

Key: Unique identifier used to get the message via script which we will see in a moment. Notice that the Key value is the same for both, only the Language field is different so that depending on the user’s language, the proper translation of the message is displayed.

Application: Used to isolate the message for Scoped Apps. In our case it will be Global.

Language: Allows you to select the Language you would like the message to be displayed for. If the I18N Language Internationalization plugin is not activated, the only option will be English.

Message: The message you wish to display for the given language selected.

Using Messages in Scripts

With our Messages created, we will now utilize them in an onChange Client script. I will give an example of the same Message displayed via Business Rule just for clarity.

For whatever reason, let’s say you would like the ITIL user completing the Incident form to receive a message and a link the Assignment Group selected whenever is changes. Again, probably not a real use case, but it is easy to demonstrate how Messages can be used.

We will create or onChange Client script to run whenever Assignment Group changes to anything but empty and display our message if the Assigned To field is not filled in. The important part is to be sure to fill in the Messages field with our Key value from the Message records we have created above.

The Script used to display our message is below.

function onChange ( control , oldValue , newValue , isLoading , isTemplate ) {

if ( isLoading || newValue === ” ) {

return ;

} if (! g_form . getValue ( ‘assigned_to’ )){ //Building our Array of values to be placed in the {0} and

//{1} palceholders that we placed in our Message records

var msgVarsArray = [];

msgVarsArray . push ( newValue );

msgVarsArray . push ( g_form . getDisplayBox ( ‘assignment_group’ ). value ); //Format the message by retrieving our message from the

//”Messages” field, and then populating it with our dynamic

//values in our above array

var msg = formatMessage ( getMessage ( “Demo Message on Incident” ), msgVarsArray ) + “.” ;

g_form . addInfoMessage ( msg );

}

}

We can now see the results of our script below with my User’s language set to English…

…and now set to Pirate!

To call this via Business Rule, the script would be as follows.

var msg = gs . getMessage ( “Demo Message on Incident” , [ current . assignment_group , current . assignment_group . getDisplayValue ()]);

gs . addErrorMessage ( msg );

Update the Filter Navigator Placeholder Text Using Messages

To change the default text on the Filter Navigator in ServiceNow’s internal UI to something other than “Filter navigator”, simply follow the steps below. Please note that this is a customization and needs to be thought through before implementing