- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2014 11:26 AM
Hi, I need to display a msg if user language is "English". I am working with Var loginLanguage = g_user.getClientData("loginlanguage"); but the language value is undefined? my current language is English. Any help is appreciated.
Solved! Go to Solution.
- Labels:
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2014 11:48 AM
There's a global variable called "g_lang" that you can use. The value would be "en" for English.
e.g. alert(g_lang) will display "en" in an alert dialog.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2015 12:08 PM
Thanks Jim!
Which table would I apply the business rule to?
I have tried catalog client scripts, catalog items, and requested items but none of them seem to be working for me.
Cheers,
- James
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2015 12:11 PM
What is your use case for getting the language? Looks like it is in the Service Catalog?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2015 12:14 PM
Yep, I have a service catalog item that has a field I would like to validate in real time.
When the onchange verifies the data, an alert message appears to say something like "Please only enter numbers".
I need this alert message to be English or French depending on the current user's language.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2015 12:36 PM
Its ugly and slow but I have a workaround for now:
in the client script:
LangAlert("hello world","Bonjour Tout Le Monde");
function LangAlert(EnText,FrText){
var UserSysID = g_user.userID;
var ga = new GlideAjax('smseAJAXOtherExpense');
ga.addParam('sysparm_name','getUserLocalizedAlert');
ga.addParam('sysparm_usersysid',UserSysID);
ga.addParam('sysparm_entext',EnText);
ga.addParam('sysparm_frtext',FrText);
ga.getXML(AjaxAlert);
}
function AjaxAlert(response){
var alertMessage = response.responseXML.documentElement.getAttribute("answer");
alert(alertMessage);
}
In a script include:
,
getUserLocalizedAlert: function() {
var UserSysID = this.getParameter('sysparm_usersysid');
var EnText = this.getParameter('sysparm_entext');
var FrText = this.getParameter('sysparm_frtext');
var gr = new GlideRecord('sys_user');
if(gr.get(UserSysID)){
if(gr.preferred_language == 'en'){
return EnText;
} else {
return FrText;
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2015 01:00 PM
You should then be able to use "alert(getMessage("u_catalog_please_enter_a_number"));" and have two Messages entries, one for English and one for French. And to help performance, add the "Messages" field to the Catalog Client Scripts form and add "u_catalog_please_enter_a_number" to that field. That will pre-load the messages instead of having to make a trip to the server to get the appropriate one.