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 07:35 AM
i added one alert in my previous reply to check the first if condition is working or not. seems like you did not update that,
Scripting rule: use alert to troubleshoot the client side script.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2019 07:53 AM
put another alert
alert(g_form.getActionName());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2019 08:15 AM
below script is working, but when condition false it is triggering UI action
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
{
alert('System Detected, you are using different time zone in Computer. Please change to Philippine/Singapore Time Zone');
return false;
}
}
}
}
issue is if return false it should not leave form right? but it is calling UI action

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2019 08:19 AM
it will, because you have called inside first if block
what exactly are you doing ? can you explain your requirement here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2019 08:39 AM
if Loggedin User Timezone is not Singapore , form should not allow the User to cancel Request