How to get the label name of a specific language

miyu
Tera Guru

I am using getDisplayValue() to get the label name of a field.
However, it is retrieved in English.
How can I get it in Japanese?

1 ACCEPTED SOLUTION

Can write a script include to get the choice labels in specified language and use that.

Example:

var ChoiceHelper2 = Class.create();
ChoiceHelper2.prototype = {
    initialize: function() {
    },
    getChoice: function(table, value, lang) {
		var grChoice = new GlideRecord('sys_choice');
		grChoice.addQuery('name', table);
		grChoice.addQuery('value', value);
		grChoice.addQuery('language', lang);
		grChoice.query();
		if (grChoice.next()) {
			return grChoice.label;
		}
	},
    type: 'ChoiceHelper2'
};

Test:

var choiceHelper = new ChoiceHelper2();
var label = choiceHelper.getChoice('incident', 'request', 'ja');
gs.info(label);

Result:

*** Script: 要求

View solution in original post

7 REPLIES 7

Hitoshi Ozawa
Giga Sage
Giga Sage

Try

gs.getMessageLang('message_key', 'ja');

Hitoshi Ozawa
Giga Sage
Giga Sage

Not sure of the question. getDisplayValue() is used to get the value of the field. 

Following code can be used to get the message in specified language.

gs.getMessageLang('message_key', 'language_id');

The label should be translated depending on the language set in user's profile. If it is desired to get a label in a different language then the chosen lang, label names are stored in sys_documentation table so it is possible to query this table to get the label string.

I didn't word it well, but we are getting the label name of the choices.
I want to get the Japanese label name of the choices.

Choices should also be translated depending on user's selected language in user's profile.

Check choices table sys_choice to make sure the translation are there.