- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2016 09:54 AM
Hi,
I am trying to send the SLA Time to Resolve value in an email when an incident is opened.
I am using the following email script:
checkETA();
function checkETA() {
var encQuery = 'slaSTARTSWITHTTR^stage=in_progress';
var eta = new GlideRecord('task_sla');
eta.addQuery('task', current.sys_id);
eta.addEncodedQuery(encQuery);
eta.query();
while(eta.next()) {
template.print('Estimated time of resolution: ' + eta.planned_end_time.getDisplayValue());
}
}
However, what I am getting in the emails, regardless of the time zone of the customer who opened the incident, is:
Estimated time of resolution: 2016-10-21 23:55:31 IDT --> Israel Daylight Time
I thought eta.planned_end_time.getDisplayValue() should show the user's timezone
Any Idea why the correct information is not displayed?
Harel
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2016 05:13 PM
Hi Harel - I get it. Would you please run this and see what you get? I think this will give us a clue:
// print eta.planned_end_time
template.print(eta.planned_end_time);
template.print(eta.planned_end_time.getDisplayValue());
// print GlideDateTime(eta.planned_end_time)
var gdt = new GlideDateTime(eta.planned_end_time);
template.print('GlideDateTime(eta.planned_end_time)');
template.print(gdt);
template.print(gdt.getDisplayValue());
// set user timezone
var timezone = Packages.java.util.TimeZone.getTimeZone(current.caller_id.time_zone);
gdt.setTZ(timezone);
template.print('set user timezone');
template.print(gdt);
template.print(gdt.getDisplayValue());
// print GlideDateTime(eta.planned_end_time.getDislayValue())
var gdt = new GlideDateTime(eta.planned_end_time.getDislayValue());
template.print('GlideDateTime(eta.planned_end_time).getDislayValue()');
template.print(gdt);
template.print(gdt.getDisplayValue());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2016 01:09 PM
Hi John,
Thanks.
This gives the time in GMT or something, although the timezone label is correct:
it shows: 2016-10-24 12:04:17 CDT
while it should be: 2016-10-24 20:04:17 CDT
Harel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2016 01:23 PM
Is this what you tried?
var timezone = Packages.java.util.TimeZone.getTimeZone(current.caller_id.time_zone);
var gdt = new GlideDateTime(eta.planned_end_time); // set using GMT
gdt.setTZ(timezone);
template.print(gdt.getDisplayValue() + '<br \>'); // output in user's time zone
I'm trying to make sure we're not "double" adjusting for the time zone.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2016 01:50 PM
OK, so almost:
with:
var gdt = new GlideDateTime(eta.planned_end_time);
template.print(gdt.getDisplayValue()); //2016-10-24 12:33:10 CDT (incorrect time with correct time zone)
//or
template.print(gdt); //2016-10-24 17:33:10 (incorrect time with no time zone)
with:
var gdt = new GlideDateTime(eta.planned_end_time.getDislayValue());
template.print(gdt.getDisplayValue()); //2016-10-24 12:33:10 CDT (incorrect time with correct time zone)
//or
template.print(gdt); //2016-10-24 20:33:10 (correct time with no time zone)
edit:
I am currently using
template.print(gdt + ' ' + current.caller_id.time_zone);
which does the job, more or less, but I'd like to get it right.
Harel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2016 02:12 PM
The first one seems correct to me, in terms of time differences. gtd is in GMT and gdt.getDisplayValue() is in user time. 2016-10-24 17:33:10 GMT is indeed 2016-10-24 12:33:10 CDT (if CDT means U.S. Central Daylight Saving Time). Can you explain what you mean by "incorrect"? Can you first determine if the gdt time is correct in GMT? What should eta.planned_end_time be in GMT?
var gdt = new GlideDateTime(eta.planned_end_time);
template.print(gdt.getDisplayValue()); //2016-10-24 12:33:10 CDT (incorrect time with correct time zone)
//or
template.print(gdt); //2016-10-24 17:33:10 (incorrect time with no time zone)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2016 04:52 PM
Hi John,
By incorrect I mean it does not show the correct time in CDT (indeed U.S. Central Daylight Saving Time).
For example, when using (from wo replies above):
var gdt = new GlideDateTime(eta.planned_end_time.getDislayValue());
template.print(gdt.getDisplayValue()); //2016-10-24 12:33:10 CDT (incorrect time with correct time zone)
//or
template.print(gdt); //2016-10-24 20:33:10 (correct time with no time zone) --> this was the time in CDT that shows in the SLA, and the time zone in the task_sla was us/central, so I expect this time to appear in the email, with CDT next to it, not 12:33:10 CDT.
Harel