Email notification translation using sys_ui_message

soumya17
Tera Contributor

Hi, I want to translate the email content automatically based on incident caller language.

below approach i followed.

I created a sys_ui_message and i have called message in email script, then i have added the mail script in notification body.
for e.g: sys_ui_message:

key- email.greeting 
message - hi - in english
Buongiorno - in italian

similarly i created all messges, below is the email script i called.
but when i raise incident with caller language as italian language, the notification content showing still in english instead of Italian content.
can anyone help..


Thanks for your feedback.

(function runMailScript(current, template, email, email_action, event) {
 
    var lang = 'en';
    var callerName = '';
 
    if (current.caller_id) {
        var caller = current.caller_id.getRefRecord();
        if (caller.isValidRecord()) {
            callerName = caller.getDisplayValue();
 
            if (caller.preferred_language) {
                var langRec = caller.preferred_language.getRefRecord();
                if (langRec.isValidRecord() && langRec.code) {
                    lang = langRec.code.toString();
                }
            }
        }
    }
        var session = gs.getSession();
        var originalLang=session.getLanguage();
        session.setLanguage(lang);
    function msg(key, lang, params) {
        return gs.getMessageLang(key, lang, params || []);
    }
 
    var baseStyle = 'font-family:Arial; font-size:18px;';
    var headingStyle = 'font-family:Arial; font-size:22px; font-weight:bold; text-align:center';
 
    // 🔹 Main heading
    template.print('<p style="' + headingStyle + '">' + msg('incident.recorded') + '</p>');
  template.print              ('_________________________________________________________________________________________');
    // 🔹 Greeting
    template.print('<p style="' + baseStyle + '">' + msg('email.greeting', current.caller_id.getDisplayValue()) + '</p>');
 
    // 🔹 Intro
    template.print('<p style="' + baseStyle + '">' + msg('incident.details.intro') + '</p>');
 
    // 🔹 Bullet points
    template.print(
        '<ul style="' + baseStyle + ' list-style-type:disc; padding-left:20px;">'
    );
 
    template.print('<li><b>' + msg('incident.number') + ':</b> ' + current.number + '</li>');
    template.print('<li><b>' + msg('incident.created') + ':</b> ' + current.sys_created_on.getDisplayValue() + '</li>');
    template.print('<li><b>' + msg('incident.caller') + ':</b> ' + callerName + '</li>');
    template.print('<li><b>' + msg('incident.shortdesc') + ':</b> ' + current.short_description + '</li>');
 
    template.print('</ul>');
 
    // 🔹 Incident link
    var url = gs.getProperty('glide.servlet.uri') + current.getLink();
    template.print(
        '<p style="' + baseStyle + '"><a href="' + url + '">' +
        msg('incident.link') +
        '</a></p>'
    );
    session.setLanguage(originalLang);
 
})(current, template, email, email_action, event);
1 REPLY 1

yashkamde
Giga Guru

Hello @soumya17 ,

Does you have checked the languages available in 'sys_ui_message' table language field and also User record language field,

As I noticed that oob on Message(sys_ui_message) table there is only one Language Present,
Screenshot 2026-01-20 180113.png

also on User Record there is only one Language i.e English,
Screenshot 2026-01-20 180208.png

 

If my response helped mark as helpful and accept the solution..