How to get Logged-In user TimeZone in Client script (OnSubmit)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2019 06:46 AM
Hi,
please help me how to get Logged-in User Time zone
i used below script in OnSubmit -Client Script working fine Native Ui side, coming to Portal side showing Javascript Error.
var id=g_user.userID;
var d;
var gr=new GlideRecord('sys_user');
gr.addQuery('sys_id',id);
gr.query();
if(gr.next())
{
d=gr.time_zone;
alert(d);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2019 06:56 AM
use glide ajax here,
client callable script include
var HelloWorld = Class.create();
HelloWorld.prototype = Object.extendsObject(AbstractAjaxProcessor, {
helloWorld:function() {
var myUserObject = gs.getUser();
return myUserObject.getTZ();
} ,
_privateFunction: function() { // this function is not client callable
}
});
client script
var ga = new GlideAjax('HelloWorld');
ga.addParam('sysparm_name', 'helloWorld');
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2019 07:01 AM
when i used GlideAjax it is working good.
i have different kind of requiremenet
when user clicked on "CANCEL " button first it should check User Time Zone, if time Zone matched then it should allow for cancellation other wise should not.
function onSubmit() {
//Type appropriate comment here, and begin script below
var id=g_user.userID;
var d;
var ajax = new GlideAjax('CallerTimeZone');
ajax.addParam('sysparm_name','timezone');
ajax.addParam('sysparm_id',id);
ajax.getXML(doSomething);
function doSomething(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
if(g_form.getActionName() == 'btn_cancel_tickets'){
if (answer.indexOf('Singapore') > 0)
{
return true;
}
else
{
alert('System Detected, you are using different time zone in Computer. Please change to Singapore Time Zone');
return false;
}
}
}
}
alert coming, Bold Code Part not Working

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2019 07:05 AM
function onSubmit() {
//Type appropriate comment here, and begin script below
var id=g_user.userID;
var d;
var ajax = new GlideAjax('CallerTimeZone');
ajax.addParam('sysparm_name','timezone');
ajax.addParam('sysparm_id',id);
ajax.getXML(doSomething);
function doSomething(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
if(g_form.getActionName() == 'btn_cancel_tickets'){
alert('is it working');
if (answer.indexOf('Singapore') > -1)
{
return true;
}
else
{
alert('System Detected, you are using different time zone in Computer. Please change to Singapore Time Zone');
return false;
}
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2019 07:32 AM
still not working....
function doSomething(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
if(g_form.getActionName() == 'btn_cancel_tickets'){
alert('it is working'); -----------------------------> not coming
if (answer.indexOf('Singapore') > -1)
{
return true;
}
else
{
alert('System Detected, you are using different time zone in Computer. Please change to Singapore Time Zone');
return false;
}
}
}
bold part not working...........