The CreatorCon Call for Content is officially open! Get started here.

gs.getUser().getLanguage() not working in scoped app script

RFJ1
Tera Contributor

Hi,

I am trying to get the current logged in users language using a server side script in a widget (scoped) . Using the   'gs.getUser().getLanguage() '   function. This is the code where I have used this function,

 var timeZones = new GlideRecord('sys_choice');
timeZones.addEncodedQuery('name=sys_user^element=time_zone^inactive=false^value!=NULL_OVERRIDE^ORvalue=NULL^language=' + gs.getUser().getLanguage());

 

But I get the following error,

find_real_file.png

 

Is there any way to solve this issue?? Any help is appreciated. Thanks in advance.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

another way

1) create script include in global scope and accessible from All Application scopes

2) in that add that script

3) then call that script include from your widget

var MyUtils = Class.create();
MyUtils.prototype = {
	initialize: function() {
	},

	getUserLanguage: function() {
		var userLanguage = this._getLanguage();
		return userLanguage;
	},
	_getLanguage: function() {
		return gs.getSession().getLanguage();
	},

	type: 'MyUtils'
};

Widget script to call it

var lan = new global.MyUtils().getUserLanguage();

OR

if you are ok with language from session then use this; it works from global + scoped app

gs.info(gs.getSession().getLanguage());

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

getLanguage() won't work in scoped app

query sys_user table with gs.getUserID() and get the language from there

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankita Sarkar
Tera Guru

Hi,

Please use the below code to get the language set by the User in the scoped app:

gs.info(gs.getSession().getLanguage());
 
Thanks,
Ankita Sarkar

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

another way

1) create script include in global scope and accessible from All Application scopes

2) in that add that script

3) then call that script include from your widget

var MyUtils = Class.create();
MyUtils.prototype = {
	initialize: function() {
	},

	getUserLanguage: function() {
		var userLanguage = this._getLanguage();
		return userLanguage;
	},
	_getLanguage: function() {
		return gs.getSession().getLanguage();
	},

	type: 'MyUtils'
};

Widget script to call it

var lan = new global.MyUtils().getUserLanguage();

OR

if you are ok with language from session then use this; it works from global + scoped app

gs.info(gs.getSession().getLanguage());

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@RFJ 

Hope you are doing good.

Did my reply answer your question?

If my response helped you please mark it correct to close the question so that it benefits future readers as well.

Regards
Ankur

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader