How can I get the time zone of a particular user? (NOT the current user)

amn
Mega Contributor

I need to get the timezone of a specific user. I have tried a simple GlideRecord query but it is not working. How can I do this?

var gr = new GlideRecord('sys_user');
gr.get('b42237741b5c41d02eeb2f82604bcb14');
gs.info(gr.first_name + ' ' + gr.last_name);
gs.info(gr.time_zone)); // returns null, also null with .getDisplayValue() and/or gr.getValue('time_zone')
4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

it worked for me

are you sure the sys_id is correct?

var gr = new GlideRecord('sys_user');
gr.get('6816f79cc0a8016401c5a33be04be441');
gs.info(gr.first_name + ' ' + gr.last_name);
gs.info(gr.time_zone);

[0:00:00.116] Script completed in scope global: script


Script execution history and recovery available here


*** Script: System Administrator
*** Script: Europe/Dublin

Regards
Ankur

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

Hm, something weird must be going on with our data. I noticed that although my user profile shows my timezone on the form, in the list view my time_zone field is empty... I put a different sys_id of a user whose timezone field is not empty in the list view and it did work.

amn
Mega Contributor

It's because my timezone (and most other users in my instance) are set to "System (US/Central) instead of just US/Central... is there a way around that without changing all users timezones?

1. Navigation search > Basic Configuration > 

2.  glide.sys.default.tz in sys_properties table

Thanks,
Shakeel Shaik 🙂