The CreatorCon Call for Content is officially open! Get started here.

How to add variables translated in notification email

moonlin
Kilo Explorer

Hi everyone, i'm new to the forum.

I'm hoping to get some guidance and assistance on coding, i asked a
similar question before and get reply from Chuck Tomasi but I didn't clarify my
requirement clearly, I get all variable sets including questions and answers,
but it didn't contain translated answers.

Ncludin

Because the question is customized, i have to create email script firstly,
maintain the notifications afterwards

Question(variable set)

Name

Answer

Translation

Type of PC required?

(multiple choice)

type_of_pc_required_zh

Desktop

Full size laptop

Compact laptop

��电脑

14寸笔记本电脑

12寸笔记本电脑

Navigate to System Notification -> Notification Email Scripts

Name:
pc_type

                      var gr_ritm = new GlideRecord('sc_req_item');

                      if(gr_ritm.get(current.document_id)){

                      template.print(gr_ritm.variables.type_of_pc_required_zh);

Navigate to
System Notification -> Notification -> What it will contain:

Here is content in

Type of PC Required

${mail_script:pc_type}

???

Preview will be:

Type of PC Required

Desktop

��电脑

My question is how to get the translated words from table 'Sys_translated'

Navigate to System Localization -> Translated name / Fields

Table

Element

Language

Value

Label (translate)

question

question_text

zh

Type of PC required

申请电脑的�类

question_choice

text

zh

Compact laptop

12寸 笔记本电脑

question_choice

text

zh

Full size laptop

14寸 笔记本电脑

3 REPLIES 3

larstange
Mega Sage

Hi



Every time you write a text to the mailbody using your notification script use gs.getMessage('value');



Then you will get the translated value based on the language setting for the user receiving the notification.



See the out of the box mailscript for "incident_has_been_closed":



(function runMailScript(current, template, email, email_action, event) {


template.print('<p><font size="5" color="#808080" face="helvetica"><strong>');


template.print(gs.getMessage('Incident has been closed') + '.');


template.print('</strong></font></p>');


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


Hi



I can get all question and answer by below scripts, but i don't know how to get the value from sys_translated:


Do you know how to edit to get the value?


printVars();


function printVars(){


      var set = new GlideappVariablePoolQuestionSet();


      set.setRequestID(current.getValue('sysapproval'));


      set.load();


      var vs = set.getFlatQuestions();


      for (var i=0; i < vs.size(); i++) {


              if(vs.get(i).getLabel() != '') {


                      template.print('       ' +   vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "\n");


              }


      }


}


Community Alums
Not applicable

Hi,

 

I know this post is old, but in case anyone is still looking for the same; I found my answer here:

https://hi.service-now.com/kb_view.do?sysparm_article=KB0784502

 

Kind regards,

Jeroen