- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2017 07:52 AM
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,
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2017 11:00 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2017 07:54 AM
Hi Lon,
getLanguage() is not available on the client side, you'll need to write a script include to get the users language and then pass it to the client with a GlideAjax.
For a good video on how to write GlideAjax check out Ask the Expert: GlideAjax - TechNow Ep 33

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2017 08:27 AM
Hi Lon,
it will not work. because getLanguage() will execute in server side .
you can try with display business rule or glide ajax.
refer the link below
http://wiki.servicenow.com/index.php?title=Getting_a_User_Object#gsc.tab=0

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2017 08:35 AM
Please find the sample script below.
Display Business Rule.:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
g_scratchpad.check= gs.getUser().getLanguage();
})(current, previous);
Client Script:
function onLoad() {
//Type appropriate comment here, and begin script below
alert(g_scratchpad.check);
}
I have created display business rule and stored value in g_scratchpad variable and used this variable in onLoad() client script.
http://wiki.servicenow.com/index.php?title=Scripting_in_Business_Rules#gsc.tab=0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2017 09:05 AM
Hi Harsh vardhan,
Thanks for the reply.
After following the instructions; the alert returns "undefined".