- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2022 06:14 AM
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,
Is there any way to solve this issue?? Any help is appreciated. Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2022 06:27 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2022 06:24 AM
Hi,
getLanguage() won't work in scoped app
query sys_user table with gs.getUserID() and get the language from there
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2022 06:24 AM
Hi,
Please use the below code to get the language set by the User in the scoped app:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2022 06:27 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2022 11:32 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader