How can I get the time zone of a particular user? (NOT the current user)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2022 07:05 AM
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')
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2022 07:14 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2022 07:22 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2022 07:25 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2022 08:19 AM
1. Navigation search > Basic Configuration >
2. glide.sys.default.tz in sys_properties table
Shakeel Shaik 🙂