The CreatorCon Call for Content is officially open! Get started here.

display users date and time in email notification

stephengunz
Kilo Explorer

Hello Community,

I am new to service now and not the best when it comes to coding so I need your help. I am wanting to send email notifications with my users groups date and time. We are part of a domain separated instance and the system time is CST and date format is "dd-MM-yyyy". I am needing email update to show in MST and "MM-dd-yyyy"

This is the script I have so far. As of right now I am getting the correct timezone I am not getting the correct date format.

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,

                  /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,

                  /* Optional GlideRecord */ event) {

// Get timezone for caller_id user and print in their timezone.

  var user = current.caller_id;

  var timeZone = String(user.time_zone);

  var updated = new GlideDateTime(current.sys_updated_on);

  var new_tz = Packages.java.util.TimeZone.getTimeZone(timeZone);

updated.setTZ(new_tz);

  template.print(updated.getDisplayValue());

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

Your help would be much appreciated

2 REPLIES 2

Rajesh Mushke
Mega Sage

Hi Stephen,




Notifications are designed for multiple recipients. Unless this particular notification is only to one individual, then it is not possible to parse every recipient out of the email log record to send in different time zones. If the notification is only to one individual, then you should be able to create multiple notifications based upon each time zone you will be sending to. Then you would have to create a method of converting the display value shown in the email to show the proper time for each date/time field per time zone as well. Doing all of this is quite time consuming and you need to ask if the amount of effort justifies the need.




it Sounds like,



How to get date in script



How to show user's local time in Email Notification



Email Notification cannot get the User Time Zone




Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke

1. The notifications are all going to users in the same timezone so I am not worried about that.



As for following these posts. I am able to get the correct date format in a separate mail scripts. However, I am not able to come up with a solution that changes the timezone like with the above script where it does not pull in the incorrect date format.



(Example I am still getting 18/07/2017 10:15:01 MDT) so I have accomplished getting the user timezone and changed from CDT to MST. But as you can see still I am unable to that without pulling the incorrect format date.