Welcome Login
Blog Photos Links

RSS Feed

Client Script Messages in ServiceNow

October 23, 2012, 1:44 pm - James Farrer

Right now I'm working with a client that has to support two different languages in their ServiceNow instance. Because of this I have been thinking more about using Messages. One area in particular that is relatively new and not often understood is Client Script Messages.

Until late last year javascript alerts and other info or error messages used in client scripts were difficult to translate. Now there is a new field on the Client Script form called Messages. When I first saw this it didn't make a lot of sense to me, but after having used it a little I'm getting to be a big fan. Any time content can be separated from function it typically means less maintenance for the code. 

The Messages field provides an easy way to access the System UI -> Messages table in Client Script. On the server side we've been able to do this by calling gs.getMessage("sample message"). Now in a few easy steps in a client script you can do it easily there too.

To set it up you put the key for any message that needs to be displayed in the script into the Messages field (one per line) and then when the form is loading those messages are looked up in the proper language in the Messages table and sent to the client along with the script so they are available. Then in your client script you can just call getMessage('message_key') to use the message.

If you don't want to mess with the Messages table while you're scripting then you can just put your message in as the parameter to getMessage and it will return the text as entered if it doesn't find anything in the Messages table that matches. I prefer putting a more descriptive name instead of the actual text but either way works.


What's New

There are currently no new items, please check back later.

Archives
2021 (2)
  September (1)
  May (1)
2019 (1)
  August (1)
2018 (3)
  August (1)
  April (1)
  January (1)
2017 (1)
  January (1)
2016 (4)
  December (1)
  November (1)
  May (1)
  January (1)
2015 (1)
  December (1)
2014 (2)
  August (1)
  February (1)
2013 (4)
  October (1)
  July (1)
  June (1)
  April (1)
2012 (11)
  December (2)
  October (3)
  September (1)
  May (1)
  April (1)
  February (2)
  January (1)
2011 (14)
  December (1)
  November (1)
  September (2)
  July (2)
  June (1)
  May (1)
  April (2)
  March (3)
  January (1)
2009 (2)
  October (1)
  June (1)
2008 (1)
  September (1)