TimeZone in Email Notification is not shown up according to the User's timezone

snowlearner
Kilo Expert

Hello Everyone,

There is a custom field on the incident form capturing the time and date. It shows the correct time according to the logged in user's timezone. But as per the update made on the ticket, an email triggers shows some information including this date and time value as well but the date and time value are not shown up according to the recipient's timezone.

For Eg : User A sees the form with the value of 20-03-2013 16:00:00 and having the time zone of GMT + 8. And User B sees the same form with the value of 20-03-2013 08:00:00 and having the time zone of GMT. So, both of the users see the correct time on the forms. But when they get the same information in the email, they receive the value of 20-03-2013 01:00:00 (this value was entered by some other user at the insertion of this ticket).

Could someone please tell me how the user is not able to receive the date time values in their timezone only as they are seeing on the forms.

thanks...

1 ACCEPTED SOLUTION

neetusingh
Giga Guru

You can give it a try -



<mail_script>


  var grt = new GlideRecord('sys_user');


  grt.addQuery('sys_id',<sys_id of the field(user) to whom the email should be sent>);


  grt.query();



  if(grt.next())


  {


  var timezone = Packages.java.util.TimeZone.getTimeZone(grt.time_zone);


  var gdt = new GlideDateTime(<date_field>); // date field which needs to be shown up according to user's timezones.


  gdt.setTZ(timezone);


  template.print("Date and Start Time:"+gdt.getDisplayValue());


  }


  </mail_script>


View solution in original post

15 REPLIES 15

just copy paste and check ... shouldn't give any errors per me ....


I am getting an error - org.mozilla.javascript.EcmaError: "TimeUtils" is not defined


give the script include name as 'TimeUtils' and copy paste


Have you created a TimeUtils script include? 'TimeUtils script include script inclide is not available ootb.



But you can alos use the below script.



var utz = gs.getUser().getTZ().toString();


var tz = Packages.java.util.TimeZone.getTimeZone(utz);


var gdt = new GlideDateTime(); //your date time field


gdt.setTZ(tz);


gs.print(gdt);


I just checked the script includes again, in the OOTB there is a script include 'TimezoneAjax' whcih contains chnageTimeZone function.



So with the Kalai's solution replace 'TimeUtils' with 'TimezoneAjax'.



So your code should be something like TimezoneAjax.changeTimeZone(<time zone value>);