logo

NJP

Translated message in the Service Portal

Import · Sep 10, 2020 · article

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:

https://docs.servicenow.com/bundle/orlando-platform-administration/page/administer/localization/task...

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:

https://docs.servicenow.com/bundle/orlando-servicenow-platform/page/build/service-portal/concept/uns...

An example:

Without Callback:

g_form.addErrorMessge(getMessage('Your text in English'))

We get a JavaScript error caused by the system:

image

With Callback:

getMessage('Your text in English', function (msg) {
            g_form.addErrorMessage(msg);
        });

We get the error message we want:

image

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://community.servicenow.com/community?id=community_article&sys_id=8d43d2bfdb4d8c50d58ea345ca961...

View original source

https://www.servicenow.com/community/developer-articles/translated-message-in-the-service-portal/ta-p/2324213