How to omit/hide time from due_date (date/time) in e-mail notification

jas101
Tera Expert

Hey guys,

Our ESS portal has recently gone live (finally!). One of our notifications contains the following line: Expect Delivery By: <b>${due_date}</b>

Displaying as: Expect Delivery By: 27/03/2015 00:00:00 PDT


We desperately want to lose the time part of this. I understand we maybe able to do this via a mail script - any help/guidance on this would be much appreciated. I'm not sure where it originated but we have this sample script below (which does not work currently):

<mail_script>

var dueDate = current.due_date.substring(0,8);

template.print("Expect Delivery By:" + "" + dueDate;

</mail_script>


I'll save the whole, how do we show time stamps based on an individual user's location (and the issue of US to non-US date format in notifications) for another day I think!


Many thanks for any help in advance.

Daniel


1 ACCEPTED SOLUTION

niedziel1
ServiceNow Employee
ServiceNow Employee

Dates are always an issue in any scripting language, aren't they?   I suspect what you are getting is the date as it is stored in the database and not the date as it is typically rendered (say, on a form).     Have you tried using the getDisplayValue() method?   current.due_date.getDisplayValue()       I think this method will return the date the format specified for your instance.


View solution in original post

3 REPLIES 3

jas101
Tera Expert

Update! Amending script to:



<mail_script>


var dueDate = current.due_date.substring(0, 10);


  1. template.print("Expect Delivery By:" + " " + dueDate);

</mail_script>



I.e. close bracket after dueDate (doh!) and changing tsubstring to (0, 10) — including space between ,   10 and between "   " has resulted in the following now printing:



Expect Delivery By: 2015-03-27



Which is great! Just need to figure out why it's gone to US date format and not kept dd/mm/yyyy!?




Thanks,


Daniel


niedziel1
ServiceNow Employee
ServiceNow Employee

Dates are always an issue in any scripting language, aren't they?   I suspect what you are getting is the date as it is stored in the database and not the date as it is typically rendered (say, on a form).     Have you tried using the getDisplayValue() method?   current.due_date.getDisplayValue()       I think this method will return the date the format specified for your instance.


Hi, yep this was exactly the issue. Working script:



<mail_script>


var dueDate = current.due_date.getDisplayValue().substring(0, 10);


template.print("Expect Delivery By:" + " " + dueDate);


</mail_script>



Many thanks.