How to detect user language in client side mobile UI?

jamesmcwhinney
Giga Guru

I need to validate a field and then trigger an alert message via a catalog client script.

That alert message needs to be bilingual.

Ordinarily (in the desktop UI), I would just use g_lang and do something like this:

function onChange(control, oldValue, newValue, isLoading) {

        LangAlert('Please only enter numbers in the quantity fields','Inscrire uniquement des nombres dans le champ de la quantité');

}

function LangAlert(EnText,FrText){

if(g_lang == 'en'){

  alert(EnText);

} else {

  alert(FrText);

}

}

...But it seems that g_lang doesn't work in client side scripting when using the mobile UI?

Is that true?

If so, what is the alternative?

Thanks!

- James

1 REPLY 1

HV1
Mega Guru

You can use Session Client Data to fulfill your requirement:


Session Client Data - ServiceNow Wiki



Initially set a session variable through a server script to store the logged in user's language; then read the value in client script.



in Server Script:


gs.getSession().putClientData('test1', 'value1');



in Client Script:


var v = g_user.getClientData('test1');



Regards,


Hardik Vora