Ways to use getMessage()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2020 11:49 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2020 11:53 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2020 11:56 AM
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..

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2020 06:53 AM
If this has answered your question, kindly mark the comment as a correct answer so that the question is moved to solved list.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2020 11:58 AM
Hi,
I believe both are working same. there is no difference in between them.
Thanks,
Kunal