Adjust the planned start/end date in notiifcation to user's time zone

Kasia5
Tera Contributor

Hi All

I have a question related to user's time zone. I set the time in CHG request and it is for example:

Planned start date: 2026-04-02 06:30:00

Planned end date: 2026-04-02 07:30:00

 

but in email notification I see thse dates as:

Planned start date: 2026-04-02 15:30:00

Planned end date: 2026-04-02 16:30:00

 

I have set the time zone as Europe/Paris. In notification template I have the script:

<mail_script>
var mlNotLib = new ml_notifications_library(current.approver);
email.setSubject([
current.sysapproval.sys_class_name.getDisplayValue(),
current.sysapproval.getDisplayValue(),
gs.getMessage("Approval request")
].join(' '));
mlNotLib.print_field(current.sysapproval.short_description, 'Short Description');
mlNotLib.print_field(current.sysapproval.company, 'Company');
mlNotLib.print_field(current.sysapproval.description, 'Description'); 
if(current.sysapproval.sys_class_name == "change_request") mlNotLib.print_field(current.group.assignment_group, 'Approval Group');
mlNotLib.print_field(current.sysapproval.priority, 'Priority');
mlNotLib.print_field(current.sysapproval.category, 'Category');
mlNotLib.print_field(current.sysapproval.type, 'Type');
mlNotLib.print_field(current.sysapproval.risk, 'Risk');
mlNotLib.print_field(current.sysapproval.impact, 'Impact'); 
mlNotLib.print_field(current.sysapproval.cmdb_ci, 'Configuration Item');
mlNotLib.print_field(current.sysapproval.start_date, 'Planned Start Date');
mlNotLib.print_field(current.sysapproval.end_date, 'Planned End Date');
mlNotLib.print_field(endLocal.getDisplayValue(), 'Planned End Date');
mlNotLib.print_field(current.sysapproval.requested_by, 'Requested By');
mlNotLib.hr();
mlNotLib.print_variables(current.sysapproval.sys_class_name, current.sysapproval);
mlNotLib.print_field(current.sysapproval.description, 'Comments');
mlNotLib.hr();
mlNotLib.mailto("Re:{0} - Approve", "Click here to approve {0}", [current.sysapproval.number]);
mlNotLib.hr();
mlNotLib.mailto("Re:{0} - Reject","Click here to reject {0}", [current.sysapproval.number]);
mlNotLib.hr();
mlNotLib.print_line("Click here to view Approval Request: ${URI_REF}", true);
mlNotLib.print_line("Click here to view ${sysapproval.sys_class_name}:  ${sysapproval.URI_REF}", true);
mlNotLib.stop_impersonating();
</mail_script>

I tried with getDisplayValue but it is not working. Is there some way to show the date in email notification depends on user's time zone?

5 REPLIES 5

ChallaR
Giga Guru

hi @Kasia5 

please find the below updated script -

Replace these lines:
mlNotLib.print_field(current.sysapproval.start_date, 'Planned Start Date');
mlNotLib.print_field(current.sysapproval.end_date, 'Planned End Date');

with -

var approver = new GlideRecord('sys_user');
var tzName = '';
if (approver.get(current.approver)) {
  tzName = approver.time_zone + ''; // e.g., "Europe/Paris"
}

// Fallback if user has no tz set
if (!tzName)
  tzName = gs.getSession().getTimeZoneName(); // fallback to session tz

// Convert Planned Start
var ps = new GlideDateTime(current.sysapproval.start_date);
var tzObj = Packages.java.util.TimeZone.getTimeZone(tzName);
ps.setTZ(tzObj);
mlNotLib.print_line('Planned Start Date: ' + ps.getDisplayValue());

// Convert Planned End.
var pe = new GlideDateTime(current.sysapproval.end_date);
pe.setTZ(tzObj);
mlNotLib.print_line('Planned End Date: ' + pe.getDisplayValue());

 

Thanks,

Rithika.ch