How to get field label information in local language

bonsai
Mega Sage

Get the label information of the dictionary record with the script below

I am localizing to a language other than English, but the values I get are in English.

Is there a way to get it in localized language?

var dic_rec = new GlideRecord("sys_dictionary");
dic_rec.addQuery("name", table_name);
dic_rec.query();
dic_rec.next();
gs.info(dic_rec.getDisplayValue("column_label") );
1 ACCEPTED SOLUTION

Sumanth16
Kilo Patron

Hi @bonsai ,

 

an 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: 要求

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda

 

View solution in original post

2 REPLIES 2

Sumanth16
Kilo Patron

Hi @bonsai ,

 

an 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: 要求

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda

 

James Chun
Kilo Patron

Hi @bonsai,

 

If you have activated another language, you should be able to translate it without writing a script.

Which field/variable are you trying to translate?

 

Cheers