How to Effectively Use gs.getMessage() for Translations in ServiceNow
- nathanlee142
- Mar 19
- 2 min read
Updated: Mar 30

As ServiceNow becomes increasingly popular among global enterprises, handling multilingual support has become essential. One common challenge developers face is translating static strings or messages within scripts to support different languages seamlessly. ServiceNow provides a handy method called gs.getMessage() for server-side scripts to tackle this issue. This article explains how to effectively use gs.getMessage() for translations, ensuring your ServiceNow applications communicate clearly and accurately to users worldwide.
Understanding gs.getMessage() and Common Issues
When scripting in ServiceNow, particularly with server-side scripts such as Business Rules or UI Actions, you might encounter situations where messages displayed to users need translation. Simply hardcoding these strings won't support multi-language environments effectively. That's precisely where gs.getMessage() steps in.
However, using this function incorrectly or incompletely can lead to untranslated or default-key strings appearing to users. Let's explore some best practices and how to avoid these pitfalls.
How to Properly Implement gs.getMessage()
To translate strings in ServiceNow using gs.getMessage(), follow these practical steps:
Step 1: Define Translation Keys and Messages
First, create translation entries in ServiceNow's System UI > Messages.
Example:
Key: first_level_of_approval
Message: First level of approval
Doing this provides clarity and consistency across your application.
Step 2: Retrieve the Translated Message in Scripts
After defining your translation messages, retrieve them in your scripts using:
ret += gs.getMessage('first_level_of_approval');
This simple method dynamically returns the correct translated message based on the user's language settings.
Practical Example:
Here's how you'd implement it in a real-world scenario:
var message = '';
if(counter_app === 0){
switch(counter_level){
case 0:
message += gs.getMessage('first_level_of_approval');
break;
// add other cases as needed
}
}
if (when.indexOf('always') === -1){
message += gs.getMessage('depends_on_selected_options');
}
Important Considerations:
If the key isn't defined in sys_ui_message, ServiceNow returns the original text used as a fallback.
To enhance clarity and maintainability, use meaningful and distinct keys rather than defaulting to English sentences directly.
Alternative Solutions for Client-Side Translation
While gs.getMessage() is great for server-side translations, you might need a different approach for client-side scripts or Service Portal. Client scripts use the getMessage() function instead, which requires adding messages to the Messages field for efficiency.
Example for Client Scripts:
ret += getMessage('first_level_of_approval');
For Service Portal translations, directly retrieving translations via getMessage() isn't supported. Instead, assign server-side translations to the data object in your widget server script:
data.more_info_reqd = gs.getMessage('More information required');
This makes translated messages accessible to client-side components.
Conclusion
Using gs.getMessage() effectively simplifies multilingual support in ServiceNow, enhancing user experience across different languages. By clearly defining translation keys, consistently implementing them within your scripts, and following best practices outlined above, you can ensure messages display correctly and professionally across all user locales.
Actionable Next Steps
Review your scripts and identify strings needing translation.
Create meaningful translation keys and entries in System UI > Messages.
Consistently apply gs.getMessage() or getMessage() methods as appropriate.
Adopting these practices will significantly improve the global readiness and user experience of your ServiceNow implementations.