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?

2 REPLIES 2

Ankur Bawiskar
Tera Patron

@Kasia5 

try this

<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');

var userTz = '';
if (current.approver && current.approver.time_zone)
	userTz = current.approver.time_zone.toString();

if (!userTz)
	userTz = gs.getSession().getTimeZoneName();

function getDateInUserTZ(dateValue, tzName) {
	if (!dateValue)
		return '';

	var gdt = new GlideDateTime(dateValue);
	var tz = Packages.java.util.TimeZone.getTimeZone(tzName);
	gdt.setTZ(tz);
	gdt.setNumericValue(gdt.getNumericValue() + gdt.getTZOffset());
	return gdt.getDisplayValue();
}

mlNotLib.print_field(getDateInUserTZ(current.sysapproval.start_date, userTz), 'Planned Start Date');
mlNotLib.print_field(getDateInUserTZ(current.sysapproval.end_date, userTz), '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>

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Thank you for your response. I tried but unfortunately planned start and end date are visible in notification as ''undefined''