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

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

GwtMessage().format() replacement?

perkinsarm
Mega Guru

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?

1 ACCEPTED SOLUTION

matthewmaxwell
Tera Expert

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?

View solution in original post

2 REPLIES 2

matthewmaxwell
Tera Expert

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?

perkinsarm
Mega Guru

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