We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How to get current logged in user time zone?

sinu2
Tera Expert

HI All,

I my email notification i need to print current logged in user time zone . But it is picking system time zone. i have tried the below codes but still no luck..

Could any one suggest how can we get logged in user time zone????????

var tz = gs.getUser();

var x = tz.getTZ();
gs.print(x); //O/P : US/Pacific-New

 

 

 

 

 

 

9 REPLIES 9

Hi,

What does logged in user mean here?

because email notification might trigger with system or in some user's session.

What is your case?

Regards

Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

 

Here logged in user means kindly check below screeen shot. In our case End User

 

find_real_file.png

This resolved my issue. Thanks!

Mike Patel
Tera Sage

you can also try

var gr = new GlideRecord('sys_user');

gr.get(gs.getUserID());

gs.print(gr.time_zone);

JerryJ071847183
Tera Sage

try below

 

var gus = gs.getUser();

 

var gr = new GlideRecord('sys_user');

gr.addQuery('sys_id',gus);

gr.query();

if(gr.next())

{

gs.print('Therefore user is in this timezone'+gr.time_zone);

}

Mark my ANSWER as CORRECT and HELPFUL if it helped.