How to achieve Dynamic Translation on message.

Goutham T
Tera Contributor

We have a requirement to translate Server-side data like, need to show info message “The incident short description is : Outlook not Working”. In this case “Outlook not Working” is Server-side dynamic data showing on form load, how to translate this message to respective language?.

1 ACCEPTED SOLUTION

Ravi Gaurav
Giga Sage
Giga Sage

Hi @Goutham T 
The gs.getMessage() method can be used to translate static text in server-side scripts. For dynamic content, placeholders can be utilized.

Example :-

var shortDescription = "Outlook not Working"; // This is your dynamic content
var message = gs.getMessage("The incident short description is: {0}", [shortDescription]);
gs.addInfoMessage(message);

In a Business Rule or Script Include, ensure the translated message is sent as part of the response:

Example in Business Rule:
if (current.short_description) {
var shortDescription = current.short_description;
var message = gs.getMessage("The incident short description is: {0}", [shortDescription]);
gs.addInfoMessage(message);
}

Client-Side 

If the message also needs to be displayed dynamically on the client-side (e.g., in a Client Script), use the getMessage() function from the g_i18n object.

Example:
g_form.addInfoMessage(g_i18n.getMessage("The incident short description is: {0}", "Outlook not Working"));



--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

View solution in original post

4 REPLIES 4

PritamG
Mega Guru

to translate server-side dynamic data like "Outlook not Working," use the gs.getMessage() method with placeholders. Store the translation keys in the System Localization > Messages table, then dynamically replace the placeholders using:

 

gs.addInfoMessage(gs.getMessage("The incident short description is: {0}", shortDescription));

 

Ensure translations for each language are added in the Messages table.

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Goutham T 

you can configure the messages in Messages table.

Then use getMessage()

Also check the link shared by Sandeep

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ravi Gaurav
Giga Sage
Giga Sage

Hi @Goutham T 
The gs.getMessage() method can be used to translate static text in server-side scripts. For dynamic content, placeholders can be utilized.

Example :-

var shortDescription = "Outlook not Working"; // This is your dynamic content
var message = gs.getMessage("The incident short description is: {0}", [shortDescription]);
gs.addInfoMessage(message);

In a Business Rule or Script Include, ensure the translated message is sent as part of the response:

Example in Business Rule:
if (current.short_description) {
var shortDescription = current.short_description;
var message = gs.getMessage("The incident short description is: {0}", [shortDescription]);
gs.addInfoMessage(message);
}

Client-Side 

If the message also needs to be displayed dynamically on the client-side (e.g., in a Client Script), use the getMessage() function from the g_i18n object.

Example:
g_form.addInfoMessage(g_i18n.getMessage("The incident short description is: {0}", "Outlook not Working"));



--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/