The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

GwtMessage Functionality

Priya Shekar
Kilo Guru

Can anyone explain me the functionality of "GwtMessage"?

4 REPLIES 4

sabell2012
Mega Sage
Mega Sage

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.


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


surajp
Kilo Guru

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

AmariMertz
Tera Contributor

The GWT Message interface allows you to create objects with the same functionality as the GWT Messaging API. The message interface supports all of the methods and properties of the messaging API. I would read https://theactionelite.com/is-a-film-degree-worth-it-7-reasons-to-pursue-this-degree/ article now so tat I could know the importance of film degree and how it could help me to find the best career opportunities in the future.