GwtMessage Functionality
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2015 05:07 AM
Can anyone explain me the functionality of "GwtMessage"?
- 10,943 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2015 01:50 PM
Priyadarshini:
You have happened onto a bit of an undocumented feature. This has been replaced with gs.getMessage(...) on the server, and getMessage(...) on the client or browser side, and should not be used.
In ServiceNow this is associated with the Localization (sic. Internationalization) capability. Based on key/message pairs stored in the Messages table (System UI -> Messages) and the user's language. This allows you to set a message up depending on spoken language (user's language).
Language Internationalization - ServiceNow Wiki (section 4.4)
With GwtMessage this functionality is only available on the browser side.
A more complex example of it's usage would be:
// Here the first parameter is actually the key for lookup in the messages table. The remaining parameters are dropped into the substitution parameters automatically.
new GwtMessage().getMessage('Published {0} of {1} records from {2}', <<string1>>, <<string1>>, <<string1>>);
Where you will probably see GwtMessage the most is with some legacy Glide dialog code.
Hope that helps!
Steven Bell.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2017 07:09 AM
The problem is that client side "getMessage" doesn't allow for string replacement. I have created an AJAX call of my own to replace "{0}" values. Is there an OOB, client side getMessage that can replace values that I'm missing? It isn't well documented.
Thanks,
AA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2020 05:56 AM
Hi All,
There is a way to pass variables to placeholders in the string within getMessage.
Use the withValues function on object returned by getMessage.
Please check the below code.
// Client script example:
function onLoad() {
// get preloaded message
var myMsg = getMessage("Logout"); // Logout
// get preloaded messsage and format
var myMsg = getMessage("The {0} says {1}!");
myMsg = myMsg.withValues(['cow', 'moo']); // The cow says moo!
// get message async
getMessage("Hello World", function(msg) { g_form.addInfoMessage(msg); } ); // Hello World
// get message async and format
getMessage("Good Morning, {0}!", function(msg) { g_form.addInfoMessage(msg.withValues([g_user.getFullName()])); } ); // Good Morning, Fred Luddy!
}
Regards,
Suraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2026 12:10 PM
That's a good overview of the GWT Message interface. It provides the same core functionality as the GWT Messaging API, making it easier to create and manage localized messages while supporting the same methods and properties.
