Goodbye gs.getMessage(), Hello sn_i18n.Message.getMessage()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
I was recently adding entries into the sys_ui_message table and noticed the "code" column. Wondering what it was for I tried to find documentation but my search didn't return much. For example, the one for Message table doesn't even mention the "code" column.
I was still curious, especially since then I also noticed that the messages had named variables!
I ended up filtering the table on code not empty to then do a code search for the keys I found.
That's when I found lines like this one
sn_i18n.Message.getMessage("app_map_core","Floor {$PH}")It passes the code first, then the key.
Then I started testing. Did it behave the same as gs.getMessage()?
First, I created a few entries in sys_ui_message.
With and without code.
With numbered variables, named variables, both.
Then I created a script.
//entry without code
gs.getMessage(<key>); //works
sn_i18n.Message.getMessage(<key>); //doesn't
sn_i18n.Message.getMessage(null,<key>); //works
//entry with a code
gs.getMessage(<code>,<key>); //doesn't work
sn_i18n.Message.getMessage(<code>,<key>); //worksWhat about passing arguments?
var arr = ['foo', 'bar'];
gs.getMessage(<key>, arr); //works
sn_i18n.Message.getMessage(null,<key>, arr); //ERROR Cannot convert array to Map
//Passing a Map then
var obj = {0: 'foo', 1:'bar'};
gs.getMessage(<key>, obj); //doesn't work
sn_i18n.Message.getMessage(null,<key>, obj); //worksNOTE: Passing arguments also works with named variables using sn_i18n.Message which makes things clearer.
ps: getMessageLang(<code>, <key>, <optional args>, <language>) also works.
pps: I did end up finding documentation
- Docs: Message - Global
- Dev Ref: Message | ServiceNow Developers
