The Now Platform® Washington DC release is live. Watch now!
04-25-2018 05:29 PM
I was looking to see if ServiceNow had a string formatting function that provides functionality similar to sprintf in other languages and came across some code that uses GwtMessage().format().
Evidently that is legacy code and GwtMessage() is not longer supported.
This Community post suggest that and notes the GwtMessage().getMessage() had been replaced by gs.getMessage().
Is there a similar replacement for the .format() function?
Solved! Go to Solution.
04-25-2018 09:44 PM
Hi perkinsarm,
I think GwtMessage.getMessage is a bit before my time, but it does look like gs.getMessage has an optional second parameter that is an array that is "(Optional) a list of strings or other values defined by java.text.MessageFormat, which allows you to produce language-neutral messages for display to users."
Is it possible that the formatting and getMessage methods were combined into GlideSystem.getMessage?
04-25-2018 09:44 PM
Hi perkinsarm,
I think GwtMessage.getMessage is a bit before my time, but it does look like gs.getMessage has an optional second parameter that is an array that is "(Optional) a list of strings or other values defined by java.text.MessageFormat, which allows you to produce language-neutral messages for display to users."
Is it possible that the formatting and getMessage methods were combined into GlideSystem.getMessage?
04-26-2018 07:18 AM
Matthew,
Yes that appears to work.
For example,
var tmpl = 'Hello {0} and {1}!';
var params = [];
params.push('Matthew','Brad');
var msg = gs.getMessage(tmpl,params);
gs.info(msg); // Hello Matthew and Brad!
Thank you,
Brad