How to obtain current time and user timezone in Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2013 02:10 AM
Hi,
We are looking for some date comparison validations in Client Scripts.
We are facing an issue where we need to obtain current date/time value for user. The issue is that:
1. We do not want to use Ajax calls in client scripts
2. If we obtain date/time from user's machine; is there a way to know user's ServiceNow Timezone ??
Also, is there an alternate way to compare current time with a date/time field on form. Any help will be greatly appreciated 🙂
Thanks,
Mayank
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2013 10:25 AM
if you don't want to make AJAX calls. I am wondering can you use business rule to compare the data/time. You could do an invalid update in the business rule if something is not right and display the message on top for the reason of invalid update.
current.time_zone = gs.getUser().getTZ();
Hope it helps!
Thanks, Faisal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2013 06:55 AM
Hi Faisal,
We thought about using Business Rules, but the issue is that we want to make a field mandatory based on comparison result of date, which will not be possible with BR. I guess using Ajax is the only solution, but we want to keep it as a last resort 🙂
Thanks,
Mayank
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2013 12:51 AM
You might be able to wrangle something (may not be perfect) using the JavaScript Date, e.g.
Date().getTimezoneOffset()
will get you the users' timezone offset, which won't necessarily match their ServiceNow TZ/TZ offset.
As far as I know, you can only get the users' TZ from SN with an AJAX call, which you already specified you don't want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2013 06:57 AM
Thanks for the update. I will try the "Date().getTimezoneOffset()" fucntion and see if it works ..
Yes I guess you are right Ajax seems to be the only way .. but we wanted to avoid that since its a heavily used form and we wanted to avoid making server calls everytime it is submitted 🙂
Regards,
Mayank