Translated message in the Service Portal
You can use Translations in many places. Here are some examples I will use in this Article:
- To set a field message
- Generate an Info or Error message
- Translate options
You can enter the translations in the [sys_ui_message]-table
Plugin for translations
Make sure you have the language you want to translate to installed:
The Callback
To set up a translated Message in the Service Portal you need to use a Callback like so:
getMessage(messageKey, callback)
This is because the getMessage without callback is not supported in the Service Portal:
An example:
Without Callback:
g_form.addErrorMessge(getMessage('Your text in English'))
We get a JavaScript error caused by the system:
With Callback:
getMessage('Your text in English', function (msg) {
g_form.addErrorMessage(msg);
});
We get the error message we want:
The script: Examples
- To set a field message
getMessage('Your text in English', function (msg) {
g_form.showFieldMsg('field_name', msg,'info');
});
- Generate an Info or Error message
info:
getMessage('Your text in English', function (msg) {
g_form.addInfoMessage(msg);
});
error:
getMessage('Your text in English', function (msg) {
g_form.addErrorMessage(msg);
});
- Translate options to add or remove:
To add the option:
getMessage('Your option in English', function(msg){
g_form.addOption('field_name','value', msg);
})
To remove you can just use:
g_form.removeOption('field_name','value');
Thanks @Mark Roethof for helping with this article.
Mark has a great article which mentions you can add the Message field to the Catalog Client script form as well as some other interesting information:
https://www.servicenow.com/community/developer-articles/translated-message-in-the-service-portal/ta-p/2324213