How to use getMessage("message key") in client script?

PhoenixMing0912
Giga Expert

Hi all,

I am using gs.getMessage() in business rule?

I am wondering how to use it in client script? I have tried g_form.getMessage(), but not working.

 

Regards,
Ming

1 ACCEPTED SOLUTION

Hi,

I believe the client side allows only 1 parameter; server side allows 2 parameters

check below links for help

Second Parameter of getMessage() on Client Side

gs.getMessage() - The Second Parameter

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

surajp
Mega 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

1__vipind
Tera Contributor

to use on the client side(on change)  use below code -

 getMessage("write  the name of key  from message table", function(msg){
alert(msg);