Join us Dec. 16 for The Community Hour, our first global virtual User Group event!

Notificatiion - Change Date Format - Email Script

Annette Kitzmil
Tera Guru

Hello,

 

I need to change the date format that is part of a notification so that it shows as MM/dd/yyyy.  On the screen shot below, my script is making the notification show "Opened:" two times and then the date for the second one is formatted correctly, but one a new line instead of the same line.  Can someone take a look at my script below and tell what I am missing here please?

 

AnnetteKitzmil_0-1710980403755.png

 

 

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {

        var dateToPrint = new GlideDateTime(current.opened_at);
        var dateFormat = dateToPrint.getDate();
        template.print('<p>Opened:</p> ' + dateFormat.getByFormat('MM/dd/yyyy'));

})(current, template, email, email_action, event);
 
Thank you
2 ACCEPTED SOLUTIONS

Basheer
Mega Sage

Hi @Annette Kitzmil ,

I think in the notification body you would have written Opened: followed by email script.

I would suggest remove Opened either at notification body or in  the email script as of template.print

 

 

View solution in original post

Harish KM
Kilo Patron

HI @Annette Kitzmil check in your email body do you have extra word opened By. You can use the below script directly,

  var dateToPrint = new GlideDateTime(current.opened_at);
  template.print('<p>Opened: ' + dateToPrint.getDate().getByFormat('MM/dd/yyyy') +' </p>');

View solution in original post

6 REPLIES 6

Thank you, I really appreciate it.

Maddysunil
Kilo Sage

@Annette Kitzmil 

Please try below code:

 

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {

        var dateToPrint = new GlideDateTime(current.opened_at);
        var dateFormat = dateToPrint.getDate();
        template.print('<p>Opened: ' + dateFormat.getByFormat('MM/dd/yyyy') + '</p>');

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

 

Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks