
- 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:15 AM
Could you try using .setDisplayValue('19:00:00')?
The documentation suggests this uses the current users TZ rather than the internal system time
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2021 03:20 AM
Or actually, having read the docs a bit more, just set the time when you instantiate the object by doing
var cutoffTime = new GlideTime(68400000);
The number being the number of milliseconds in 19 hours - that should take your instance timezone into account:
Example
This example shows adding 10 seconds to midnight (UTC), which is then adjusted for the time zone in which the instance resides. In this case, -8 hours from UTC.
var gt = new GlideTime(10000);
gs.info(gt.getDisplayValue());
Output
16:00:10

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2021 03:21 AM
Hmm, will try this one. I'd not looked at the ms option as I kind of felt the "readable" alternative should work, and if ms vs time are different I find it a little odd ...
Let me try this and see what it does ...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2021 03:33 AM
Nope, the ms option does the same as the time
var today = new GlideDate();
var cutoffTime = new GlideTime(68400000); // 19:00:00
// cutoffTime.setValue('19:00:00');
var approve_by = new GlideDateTime(today.getDisplayValue() + " " + cutoffTime.getTime());
log += "\nCutoff date: " + approve_by;
That log shows me "2021-04-09 00:00:00" - 5 hours ahead of where I want it, i.e. UTC+7.
On the plus side, setting by ms and time work the same, which is good 😄