Best Practice

Harness the Power of Messages

When creating custom code, for values that are text-driven and/or capable of changing often (things like the “Submit” text or “Contact the Help Desk” footer button) make sure to include those values in the Messages table.

ServiceNow delivers with a table called Messages OOB. You don’t even have to extend it as you can either assign a specific message to a unique application or add a prefix to the key. Then you can add a module to the Content Management application that only brings in the collection of Messages within the application or that start with your prefix. What I end up doing a lot is setting the “Key” value with cms_ and then I create a module under CMS that brings is any key that starts with “cms_”.

There are 2 major reasons to use Messages:

  1. Your content editors can quickly get in and edit the messages table much easier and faster than having to work through the development team to update a text value.
  2. If you are ever considering enabling localization, the additional languages will reference the language field and serve up the correct message.

The syntax is really simple. Just include ${gs.getMessage(‘replace this’)} in your code. Swap out the ‘replace this” code with whatever the key is you have set. Done!

It’s much quicker when coding to just hard code in the value, but for scalability and ease of future updates, Messages win every time.

Leave a Reply