How to get Logged-In user TimeZone in Client script (OnSubmit)

chanikya
Tera Guru

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);
}

 

13 REPLIES 13

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. 

put another alert 

 

alert(g_form.getActionName());

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

it will, because you have called inside first if block 

 

what exactly are you doing ? can you explain your requirement here 

if Loggedin User Timezone is not Singapore , form should not allow the User to cancel Request