Email Notification cannot get the User Time Zone

Mohamed Faizel
Giga Expert

Hi,

When we receive the email notifications from service now including work notes in the body, it has shown the instance time zone and time and it does not fetch the users time zone with latest updated time in email.

Can any one please help on this?

22 REPLIES 22

I should add, if you put the mail script into the email body html, it will move this to a new mail script record and automatically change your script to a reference to the script. It's a nice feature to carry over legacy mail scripts.


ashleyhaglin
Kilo Contributor

Instead of just changing a specific field's time to the time zone of the current user has anyone been able to change the time stamp included in the comments in the email? For example when we send an email when comments are added it includes the time stamp and user that made the comment, I am looking to change that time stamp so it shows the timezone based on the user receiving the message instead of always showing the system timezone.


narenreddy
Giga Guru

You can use below email script and script include to show the time in User timezone(assigned to/contact).


1) Email Script:- I am getting last 5 journal entries to print in the email body.



var max_to_process = 5;


var processed = 0;


var ut = current.contact.time_zone;


//If there is not timezone then set it to US/pacific as per system time zone.


if(!ut)


ut = "US/Pacific";


var journalEntry = new GlideRecord('sys_journal_field');


journalEntry.addQuery('element', 'comments');


journalEntry.addQuery('element_id',current.sys_id);


journalEntry.orderByDesc('sys_created_on');  


journalEntry.query();


while(journalEntry.next() && (processed < max_to_process)) {


var dt = journalEntry.sys_created_on;


var str = journalEntry.value;


var str1 = str.replace(/\[code]/g, '');


var str2 = str1.replace(/\[\/code]/g, '');


var user1 = journalEntry.sys_created_by;


  var gr = new GlideRecord('sys_user');


        gr.addQuery("email",user1);


        gr.query();


        if(gr.next()){


  user1 = gr.name;


  }


var dt1 = new getUsersTime().getUserTime(dt,ut);


template.print('<div><p><font size="2" face="helvetica"><strong>');


template.print('<hr>');


template.print(dt1+"   -"+user1);


template.print('</strong></font></p></div>');


template.print('<p><font size="2" face="helvetica">' + str2 + '</font></p>');


processed ++;


}


})(current, template, email, email_action, event);



Script Include:-



var getUsersTime = Class.create();


getUsersTime.prototype = {


      initialize: function() {


      },


getUserTime: function(date,usertimezone){


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


  var gdt = new GlideDateTime(date);


  gdt.setTZ(timezone);


  var set1 = gdt.getTZOffset();


  gdt.setNumericValue(gdt.getNumericValue() + set1);



        return gdt;


  },


      type: 'getUsersTime'


};