Pls let me know correction in the script

BanuMahalakshmi
Tera Contributor

Hi,

 

I have written script include to translate the text value of field catalog item because this field not translating non-english language.  Then i passed the value to notification email script. This script correctly translating catalog item non - english language but if it is english - its show undefined. because there is no record for English language into translated_Text table. pls let me know any correction required in the script to display english language also with out any error:

 

    gettranslationMessage: function(fieldname, language,documentkey) {
        var res;
gs.log("loop running script");
        var translate = new GlideRecord('sys_translated_text');
        translate.addEncodedQuery('fieldname=' + fieldname + '^language=' + language + '^documentkey=' + documentkey);
        translate.query();
        if (translate.next()) {
            res = translate.value;
        }
        return res;
    },
Notification Email Script:
            var language = gr.requested_for.preferred_language;
            var documentkey = gr.cat_item.sys_id;
            var fieldname = "name";
gs.log("The fieldname, catalog sysid, language="+language);
gs.log("The fieldname, catalog sysid, language="+documentkey);
gs.log("The fieldname, catalog sysid, language="+fieldname);
            var callIt = new ArconicRitmApprovalUtils().gettranslationMessage(fieldname, language, documentkey);
            gs.log("callit value="+callIt);
 
            template.print('<tr style="height:13px; font-family:Calibri; font-size:11px; text-align:left">');
            template.print('<td style="width: 25%; height: 13px;">' + gr.number + "</td>");
            template.print('<td style="width: 25%; height: 13px;">' + callIt.toString() + "</td>");
            template.print('</tr>');
        }
1 ACCEPTED SOLUTION

Marco0o1
Tera Sage

Hi @BanuMahalakshmi ,

 

If the translation for your field not exist just return the value of the field. Try with this:

   gettranslationMessage: function(fieldname, language,documentkey) {
        var res;
gs.log("loop running script");
        var translate = new GlideRecord('sys_translated_text');
        translate.addEncodedQuery('fieldname=' + fieldname + '^language=' + language + '^documentkey=' + documentkey);
        translate.query();
        if (translate.next()) {
            res = translate.value;
        } else {
      res = fieldname // I think the fieldname is the text you want to translate or documentkey you now which is the correct.
}
        return res;
    },


Hope that help you.

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@BanuMahalakshmi 

Did you explore dynamic translation on email notifications starting from Tokyo?

How to setup dynamic translation on email notifications for first time? 

Also check this

Multilingual email notifications 

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

Marco0o1
Tera Sage

Hi @BanuMahalakshmi ,

 

If the translation for your field not exist just return the value of the field. Try with this:

   gettranslationMessage: function(fieldname, language,documentkey) {
        var res;
gs.log("loop running script");
        var translate = new GlideRecord('sys_translated_text');
        translate.addEncodedQuery('fieldname=' + fieldname + '^language=' + language + '^documentkey=' + documentkey);
        translate.query();
        if (translate.next()) {
            res = translate.value;
        } else {
      res = fieldname // I think the fieldname is the text you want to translate or documentkey you now which is the correct.
}
        return res;
    },


Hope that help you.