What is "code" field in sys_ui_message table

Community Alums
Not applicable

I wanted to understand what is "code" field on the message table form??
What is the use of this?? when we use this??

UTSAVJAISWAL_0-1749629678795.png


Thanks in Advance
Utsav

1 REPLY 1

ugutha
Tera Contributor

Hi @Utsav JAISWAL ,

 

The “code” field in the sys_ui_message table in ServiceNow is used to store a unique key (also referred to as the message key) that identifies a localized UI message.

Purpose of the code Field:
• It acts as a message identifier that can be referenced in scripts or UI policies to display localized messages.
• It supports internationalization (i18n) by mapping the same code to different message texts based on the user’s language locale.



How It’s Used:
• You reference the code like this in your server/client script:

gs.getMessage('your_code_here')

or in a client script:

g_scratchpad.message = g_user.getMessage('your_code_here');


• ServiceNow will return the message text that corresponds to the code in the user’s language.



Example:

If you have a row in the sys_ui_message table like:
• Code: error.missing_field
• Message: This field is required.

Then in your script:

var message = gs.getMessage('error.missing_field');
// message = "This field is required."

If the same code is defined in another language (e.g., French), French users will automatically see the translated message instead.

Hit Helpful if this was helpful for you.