Second Parameter of getMessage() on Client Side

Mike McCall
Giga Guru

I was recently inspired by Chuck Tomasi's post on gs.getMessage() - The Second Parameter, but when I tried to add a second parameter to the client-side getMessage() function, it didn't seem to work.

Does anyone know if the client-side getMessage() function does not accept a second parameter like the server-side gs.getMessage() does?

(If it matters, we're currently on Eureka Patch 7.)

1 ACCEPTED SOLUTION

sergiu_panaite
ServiceNow Employee
ServiceNow Employee

Hello Michael,



getMessage(String) on client side uses only one parameter vs gs.getMessage(String, Object) that can use a second parameter.



Regards,


Sergiu


View solution in original post

15 REPLIES 15

Ooh, interesting! I'll have to try this out (and swap it in for "Correct Answer" if it works).

Out of curiosity, were you referencing any available documentation to discover this, or did you have to do your own sleuthing/trial-and-error?

 

Got this from servicenow internal team. I don't know why service now don't update the documentation.

eden_shavit
ServiceNow Employee
ServiceNow Employee

Hi, I have encountered a problem using the withValues function, I get the following error: "getMessage(...).withValues is not a function".
Do you know what can be the reason for this error?

karthik ande
ServiceNow Employee
ServiceNow Employee

getMessage(string) has only one parameter. But there is a way to pass parameters to the string.
For example:
getMessage("Creating new version number {0} and updating in {1}").withValues([variable1, variable2]);
withValues function can be called on getMessage to pass the parameters.

What is this "withValues" method?  It's not a base JavaScript method (that I've found) and does not seem to be documented anywhere by ServiceNow, which brings up the idea of how safe is it to use?

It is a nice way to do the string replacements, but we could just use the "replaceAll" method and feel safe about it.  Like:

var message = getMessage("Creating new version number {0} and updating in {1}");
message = message.replaceAll("{0}", variable1);
message = message.replaceAll("{1}", variable2);

Not as pretty, but safer?