What is "code" field in sys_ui_message table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2025 01:14 AM
I wanted to understand what is "code" field on the message table form??
What is the use of this?? when we use this??
Thanks in Advance
Utsav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2025 01:27 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2025 03:46 AM
Do you have any source link to this information?
A unique key that identifies a localized UI message is stored in field Key [key], Code [code] is a different field.
Documentation reference: https://www.servicenow.com/docs/bundle/zurich-platform-administration/page/administer/localization/r...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2025 03:58 AM
Personally , i have never used this field in message table.
But by looking at the existing data , if feels like it can be used to store a name of system property type of values like "com.glide.sys.fencing.cross_scope_access.crossscopefeedback"
Best, would be to crosscheck the existing data to get an idea.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
I might have found an answer.
Looks like the code field is used to distinguish between messages with identical message keys and/or to group messages by an arbitrary identifier.
There is a different "getMessage" function from the well-known one, which can query for the Code of a message:
https://www.servicenow.com/docs/r/api-reference/server-api-reference/sn_i18n.messageAPI.html
The regular GlideSystem.getMessage function takes the key of a message as the first argument.
The sn_i18n.Message.getMessage function linked above takes the code as the first argument and the key as the second one.
Here are some OOTB Message with Codes:
Query them like this (tested in background script):
(function translationTest(){
var message = sn_i18n.Message.getMessage('sn_instance_clone', 'cleanup_script_active_info');
console.log('Test translation: message -> ' + message);
})();To get a result like this:
*** Script: Test translation: message -> Active: script runs on all clones. Inactive: script is skipped. Applies across all clone profiles.