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 08:45 AM
comment the first if block , just check the user time zone is Singapore or not

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2019 08:24 AM
function onSubmit() {
//Type appropriate comment here, and begin script below
var id=g_user.userID;
var button=g_form.getActionName();
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(button == 'btn_cancel_tickets')
{
alert('working')------coming...
if (answer.indexOf('Singapore') > -1)
{
return true;
}
else
{
}
}
else{
alert('System Detected, you are using different time zone in Computer. Please change to Philippine/Singapore Time Zone');
return false;
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2019 08:04 AM
Hi,
You can try the given method in Script include and call this script include from client script :
gs.print(gs.getProperty("glide.sys.default.tz"));
[ Architect | Certified Professional]
Was this response helpful? If so, please mark it as ✅ Helpful and ✅ Accept as Solution to help others find answers.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2019 08:21 PM
any update on this thread.
If i answered your query, kindly mark it as correct and helpful
If it's empty, it's America/Los Angeles
OR
var myUserObject = gs.getUser()
gs.print(myUserObject.getTZ()); -- returns the timezone of the current user
OR
var gdt = new GlideDateTime();
gs.print("Value : " + gdt.getUserTimeZone()); --TimeZone object for the current user.
To know more about timezone you can have a look at given link.
Thank you!