Optaining user language in a catalog script with g_user?

jesusemelendezm
Mega Guru

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.

1 ACCEPTED SOLUTION

Jim Coyne
Kilo Patron

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.


View solution in original post

20 REPLIES 20

OK, good.


Would you happen to know what the equivalent is for client side scripting in the mobile UI ?


g_lang doesn't seem to work there =o(


No, sorry, I do not.   Would have to dig around.   I wonder if CapaJC might know?


CapaJC
ServiceNow Employee
ServiceNow Employee

I had a look, and as far as I can tell, the mobile UI doesn't currently have a global variable that will give you that information. g_form and g_user exist, but neither will give you the user's language that I could tell.


The best workaround I could come up with is to create a "Display" Business Rule on whatever table you need it on with the following code to add the language to the scratchpad:



(function(){


  g_scratchpad.u_language = gs.getUser().getLanguage();


})();



You can then use "g_scratchpad.u_language" in a Client Script.   Works with both the Desktop and Mobile UIs.



I was trying to use Session Client Data, but that was not even working in the full Desktop UI for some reason.