Is there a way to get the display value for a language besides the current language?

seberly
Giga Expert

I know by using .getDisplayValue() will return the display value for the currently selected language, but I am looking for a way to get the display value for a different language. For example, I want to get the German display value no matter what language I have selected as my preference.

Thoughts?

Thanks,
Scott

3 REPLIES 3

CapaJC
ServiceNow Employee
ServiceNow Employee

I don't know of a way to get it directly, but you could do the following:



var lang = gs.getSession().getLanguage(); // puts the user's current language in a variable
gs.getSession().setLanguage("es"); // sets the session language to whatever you want, this one is Spanish
gs.print(gr.title.getDisplayValue()); // prints the Spanish translation of the "title" field of the GlideRecord variable "gr"
gs.getSession().setLanguage(lang); // sets the langauge back to what it was


Interesting approach. Since we only have 3 languages available I believe we just did the following:



if(value == '<english value>' || value == '<german value>' || value == '<french value>')



...instead of:



var translation = <code to get translation of the field value>;


if(value == translation)


Uttam Sai
Tera Contributor

Hi @CapaJC 

I have been trying below script , but the value of the producer short description is still in session language . Could you please help .

 

var lang = gs.getSession().getLanguage();

if (producer.problem_subcategory_team_center.getDisplayValue() == 'OTP') {
    gs.getSession().setLanguage("en");
    short_desc = producer.product_line.getDisplayValue() + ' - ' + producer.issue_category.getDisplayValue();
    gs.getSession().setLanguage(lang);
} else {
    short_desc = producer.problem_short_description;
}