Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

System time zone and user's time zone in email

oharel
Kilo Sage

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

1 ACCEPTED SOLUTION

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());


View solution in original post

20 REPLIES 20

Hi Chuck,



I have. I would prefer using something that won't mess up my scripts in the future, of-course.


The following script gives the correct time, but with incorrect time zone, so the result would be 2016-10-28 00:00:00 IDT instead of 2016-10-28 00:00:00 CDT


var tz = gs.getSession().getTimeZone();


var gdt = new GlideDateTime(eta.planned_end_time);


//var timezone = Packages.java.util.TimeZone.getTimeZone(current.caller_id.time_zone);


gdt.setTZ(tz);


template.print(gdt.getDisplayValue() + '<br \>');



harel