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

@RFJ 

Thank you for marking my response as correct.

If my response helped please mark it correct and close the thread.

Regards
Ankur

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

@Ankur Bawiskar Yeah I have marked it as correct. However I have another query,

gs.getUser().getUserByID() also does not work in scoped app. Is there any other way around without using GlideRecord and querying the table?

I don't think any workaround for that

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

mahmoudabde
Tera Contributor

In the Default Value for the Var you can use this I used for location and Dept and worked for me 

javascript: var loc; var gr=new GlideRecord("sys_user"); gr.addQuery("sys_id",gs.getUserID()); gr.query(); if(gr.next()) { loc=gr.location;} loc;

javascript:  var dep; var gr=new GlideRecord("sys_user"); gr.addQuery("sys_id",gs.getUserID()); gr.query(); if(gr.next()) { dep=gr.department;} dep;