Translate the Title Text of URL in email script

anirban300
Kilo Guru

Hello Everyone,

 

I want to translate the URL Title text. Below is the email script. In the below script I want to translate the text "" in different language. Can I use "gs.getMessageLang()" here and if yes how can I do it?

 

Email Script:

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {

// Add your code here
var language = current.user.preferred_language;

template.print('<p><span style="font-family: arial, helvetica, sans-serif; font-size: 12pt;"><a href="/esc?id=take_survey&amp;instance_id=${sys_id}"><strong>Take the User Satisfaction Survey</strong></a></span></p>');


})(current, template, email, email_action, event);

1 ACCEPTED SOLUTION

Arjunsuhass
Giga Contributor

Yes, you can use "gs.getMessageLang()" to translate the text in different langages.
Here's an updated version of the email script that uses "gs,getMessage()" method to retrieve the translates message:

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {

// Add your code here
var language = current.user.preferred_language;
gs.setRedirectURL(current);

template.print('<p><span style="font-family: arial, helvetica, sans-serif; font-size: 12pt;"><a href="/esc?id=take_survey&amp;instance_id=${sys_id}"><strong>' + gs.getMessage("Take the User Satisfaction Survey", null, language) + '</strong></a></span></p>');

})(current, template, email, email_action, event);

In this updated script, we pass the message key "Take the User Satisfaction Survey" to the "gs.getMessage()" method along with the language parameter obtained from the "current.user.preferred_language" field. The method then returns the translated message based on the specified language.

Make sure to create message translations for all languages you want to support in the "System UI > Messages" table.

View solution in original post

4 REPLIES 4

-O-
Kilo Patron
Kilo Patron

Yes, you can use gs.getMessageLang() (but if you do use translated e-mails you need to use gs.getMessage().

However

var language = current.user.preferred_language;

is most likely wrong.

In order to tell you how you could arrive to the proper language, one would need to know which table current represents and how the recipient is determined.

Arjunsuhass
Giga Contributor

Yes, you can use "gs.getMessageLang()" to translate the text in different langages.
Here's an updated version of the email script that uses "gs,getMessage()" method to retrieve the translates message:

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {

// Add your code here
var language = current.user.preferred_language;
gs.setRedirectURL(current);

template.print('<p><span style="font-family: arial, helvetica, sans-serif; font-size: 12pt;"><a href="/esc?id=take_survey&amp;instance_id=${sys_id}"><strong>' + gs.getMessage("Take the User Satisfaction Survey", null, language) + '</strong></a></span></p>');

})(current, template, email, email_action, event);

In this updated script, we pass the message key "Take the User Satisfaction Survey" to the "gs.getMessage()" method along with the language parameter obtained from the "current.user.preferred_language" field. The method then returns the translated message based on the specified language.

Make sure to create message translations for all languages you want to support in the "System UI > Messages" table.

Uttam Sai
Tera Contributor

Hi @Arjunsuhass ,
Could you please help me how to use "gs.getMessage()" for the below part of email script.

template.print('<div>Hello ${task.assigned_to.name},</div><div>&nbsp;</div><div>This is a friendly reminder that your task "${task.u_activity_type}" on ${task.parent.number} still requires your action. Please take the required actions, then complete this task as soon as possible in the ServiceNow portal.</div><div>&nbsp;</div><div>You can access your onboarding case from the link below to complete your task.</div>');
}
I have posted a new question here