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

Thank you.
I have already set the Japanese labels for the choices.
I am specifically using getDisplayValue() in the Scheduled script to get the label names of the choices.
The "Run as" in the Scheduled script is "Administrator".
The language setting for Administrator is "Japanese".
However, English labels are retrieved.
Is there a 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: 要求

Thank you! It worked fine.