
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2021 03:03 AM
I am trying to assign a "latest response date" in a workflow, so I can timeout the whole thing and end it if the customer doesn't respond in time.
To do this, I am setting:
var today = new GlideDate();
var cutoffTime = new GlideTime();
cutoffTime.setValue('19:00:00');
workflow.scratchpad.approve_by = new GlideDateTime(today.getDisplayValue() + " " + cutoffTime.getTime());
When I display this to the customer on the Case though, I see:
Approve by: 2021-04-09 02:00:00
Which is obviously not correct, and I assume is using the wrong timezone. Our instance is set to Sweden/Stockholm (UTC+2), and my user has the same timezone, so why is this producing a time in a different TZ?
How can I ensure that (a) My display info is correct, and (b) that I _actually_ have the right time (7pm tonight, local time), when I use this value later on in a check?
Solved! Go to Solution.
- Labels:
-
Workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2021 03:21 AM
Hi,
getDisplayValue() would always give the time in user's local timezone and not GMT
Can you try this
var today = new GlideDate();
var cutoffTime = new GlideDateTime();
cutoffTime.setDisplayValue(today + ' 19:00:00');
workflow.scratchpad.approve_by = new GlideDateTime(today.getDisplayValue() + " " + cutoffTime.getDisplayValue().toString().split(' ')[1]);
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
04-09-2021 03:19 AM
This is almost certainly because the system default timezone is not the same timezone as you (e.g. you might be set to UK, but the system timezone might be set to LA (default)). Importantly, this could be for very valid reasons,
Check out this part of the Developer API details which show how to take TimeZone's into account with GlideDateTime,
Many thanks,
kind regards
Director of Globalization Deployment, Internationalization

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2021 03:20 AM
Nope. I'm Stockholm/Sweden and so is the system. The TZ I'm getting appears to be PDT for some weird reason
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2021 03:22 AM
Yes, but dont' forget GlideDateTime uses the time zone of the "current" user. Which might be system if the WF has been interrupted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2021 03:19 AM
So
19:00:00
is local time?
If yes, than you are providing a local time where a UTC one is expected.
GlideDateTime constructor expects a UTC time as argument.
Try to create a new instance of GlideDateTime, and set the value in a separate instruction using .setDisplayValue().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2021 03:21 AM
Hi,
getDisplayValue() would always give the time in user's local timezone and not GMT
Can you try this
var today = new GlideDate();
var cutoffTime = new GlideDateTime();
cutoffTime.setDisplayValue(today + ' 19:00:00');
workflow.scratchpad.approve_by = new GlideDateTime(today.getDisplayValue() + " " + cutoffTime.getDisplayValue().toString().split(' ')[1]);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader