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

comment the first if block , just check the user time zone is Singapore or not 

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

}


}

 

Chavan AP
Tera Guru

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

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!

Chavan AP
[ Architect | Certified Professional]

Was this response helpful? If so, please mark it as Helpful and Accept as Solution to help others find answers.

Harsh Vardhan
Giga Patron

any update on this thread. 

 

If i answered your query, kindly mark it as correct and helpful