Ways to use getMessage()

Krishna119
Kilo Contributor

Recommended way to use getMessage() is 

var message = gs.getMessage("This is the message with params {0}", param);
gs.addInfoMessage(message);

Alternately, it can also be written as 

var message = "This is the message with params {0}";
gs.addInfoMessage(gs.getMessage(message,param));

and it works. 

Is there any problem in second way?

 

5 REPLIES 5

Chander Bhusha1
Tera Guru

Hi krishna,

I would prefer the first one as you will get to know the parameters in the getMessage and while calling the message it will have only one parameter. and entire message is returned in one variable only

var message = gs.getMessage("This is the message with params {0}", param); gs.addInfoMessage(message);

 

There is no problem in using the second as both are same only. But ideally in all servicenow OOB scripts they are using the first one only.

Mark helpful and correct if it helps.

Thanks,

CB

asifnoor
Kilo Patron

Hello Krishna,

I don't see any different in both ways. In the 2nd way, you are substituting a string which internally contains the same string as first method. So internally you are using method 1 only.

Kindly Mark the comment as correct answer if it answers your question..

 

If this has answered your question, kindly mark the comment as a correct answer so that the question is moved to solved list.

Kunal Varkhede
Tera Guru

Hi,

 

I believe both are working same. there is no difference in between them. 

 

Thanks,

Kunal