Outage time format in email notification
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2024 01:37 PM
Hello everyone,
We have a requirement to update the email notification to show only time the outage begin or end.
For this, I created a mail script to parse only the hour:minutes from the Outage Begin field.
This part is working fine, but is passing in 24h format, like below:
Here is the mail script I did:
(function runMailScript(current, template, email, email_action, event) {
var curGdt = current.end.getDisplayValue().substring(11, 16);
template.print(curGdt);
})(current, template, email, email_action, event);
How should I do to pass the time in 12h format including AM/PM?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2024 09:56 PM
Hi Luiz,
This should achieve your desired outcome. Since there is no getByFormat() method available for GlideDateTime, we can pass the curGdt GlideDateTime object to the GlideDate method and return the time formatted with AM/PM.
(function runMailScript(current, template, email, email_action, event) {
var curGdt = new GlideDateTime(current.end);
var userFormattedDate = formatDate(curGdt);
template.print("Outage end: " + userFormattedDate);
}
)(current, template, email, email_action, event);
function formatDate(date) {
var gdt = new GlideDate();
gdt.setValue(date);
var time = gdt.getByFormat('hh:mm a');
return time;
}
Regards,
Kyle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2024 06:32 AM
Hi @Community Alums
Thanks, very helpful, we got very close, but is returning the UTC time instead of the system time, US Eastern time. Do you happen to know why?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2024 09:26 AM
Hi @Luiz Lucena ,
You can refer below code to change or set your current timeZone
var tz = gs.getSession().getTimeZone();
var gdt = new GlideDateTime();
gdt.setTZ(tz);
Please mark my answer correct and helpful if this works for you
Thanks and Regads
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2024 09:41 AM - edited 05-13-2024 09:46 AM
Thanks, @Community Alums
Will try to include this piece into the one you provided earlier.
Here is the version I tried, but it insists in showing UTC time.
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
var tz = gs.getSession().getTimeZone();
var curGdt = new GlideDateTime(current.begin);
var getDate = new GlideDate();
getDate.setValue(curGdt);
getDate.setTZ(tz);
var getTime = getDate.getByFormat('hh:mm a');
template.print(getTime);
})(current, template, email, email_action, event);