Get logged in user language into script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2023 04:53 AM
Hi All,
I working with script include . I want to get language of the logged in user into script include.
I tried this to use in script include but , it is not working :
var language = gs.getUser().getLanguage();
please tell me how to get language of the logged in user.
Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2023 07:13 AM - edited 06-23-2023 07:26 AM
can you try
var userPref = new GlideRecord("sys_user_preference");
userPref.addQuery("user", gs.getUserID());
userPred.addQuery("name" "user.language");
userPref.query();
if (userPref.next()) {
gs.info(userPref.value);
}
If my answer has helped with your question, please mark it as correct and helpful
Regards,
Ravi Chandra.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2023 05:23 AM
You can use gs.getSession().getLanguage(). This will give you the language opted by Logged in user
But don't expect the code to return full name of language like English or Arabic. The reason being servicenow stores language preference in terms of language id/code.
So for English, language code is en and for Arabic, language code is ar
Similarly you can find the code for other languages in below link (You can use the mapping in this link for getting full name of language)
http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2023 05:52 AM
you can try the below code: