How can I pass information from g._user in client script?

Lon Landry2
Tera Contributor

I am trying to create a client script to display a system message based on the users language.

(This is a small part of what I am trying to do, but after failing for 20 hours; I am trying small bites.)

This is the code I am using:

function onLoad() {

var language = g_user.getLanguage();

    g_form.addInfoMessage(language);

}

I have also tried variations using

var loginLanguage = g_user.getClientData("loginlanguage");

With correct variables set,,,

And GlideAjax...

 

Thanks for your time,

1 ACCEPTED SOLUTION

as per my understanding it is acting like this way just because of we are dealing in different   scope. when you will try the same thing in global then it will work perfectly.


may i know your exact requirement?


View solution in original post

11 REPLIES 11

What I am trying to do is show / hide fields based on the users language (browser setting - not system). g_lang returns the browser language settings




The fields that I am showing or hiding are reference fields.



The records in the tables linked to the reference fields are language specific.




The reasoning is uploading hundreds or thousands of translations for a custom scoped application.



(To get into the SNOW store , nothing in the app can be in Global app, so ServiceNow's easi-import or other import options cannot be used).




I plan on publishing all of my findings on Adding Translations to Custom Scoped Apps in the community (about 20 slides) in Spanish and English. And would be happy to pass it on for other language translations (Hindi, Urdu, etc.).


Thanks; I could not find any info leading me to g_lang.


It worked great for my solution.



function onLoad() {


//Type appropriate comment here, and begin script below



if(g_lang == 'en'){


g_form.setDisplay<http://form.setDisplay>('u_eqpt_colores', false);


g_form.setDisplay<http://form.setDisplay>('u_eqpt_colors', true);


g_form.setDisplay<http://form.setDisplay>('u_cores0_cor', false);


}



else if(g_lang == 'es'){


g_form.setDisplay<http://form.setDisplay>('u_eqpt_colores', true);


g_form.setDisplay<http://form.setDisplay>('u_eqpt_colors', false);


g_form.setDisplay<http://form.setDisplay>('u_cores0_cor', false); }



else if(g_lang == 'pb'){


g_form.setDisplay<http://form.setDisplay>('u_eqpt_colores', false);


g_form.setDisplay<http://form.setDisplay>('u_eqpt_colors', false);


g_form.setDisplay<http://form.setDisplay>('u_cores0_cor', true);



}


}