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

Have you tried the the function <date time>.getUserTimeZone().


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>


Thanks Neetu!


This has made my requirement worked.


what if want this for the case table : have tried this but not working.

 

var userId = gs.getUserID();
var grt = new GlideRecord('customer_contact');

grt.addQuery('sys_id', userId);

grt.query();

if (grt.next()) {

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

var gdt = new GlideDateTime();
gdt.setTZ(timezone);

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

}