- 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-31-2022 06:05 AM
Thank you for marking my response as correct.
If my response helped please mark it correct and close the thread.
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
02-01-2022 12:51 AM
gs.getUser().getUserByID() also does not work in scoped app. Is there any other way around without using GlideRecord and querying the table?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2022 01:00 AM
I don't think any workaround for that
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2025 05:51 AM
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;