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

 

 

Please hit like button if my suggestion has helped you in any way.
Please mark correct if my response has solved your query.

Cheers,
Mohammed Basheer Ahmed.

View solution in original post

Harish KM
Kilo Patron
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>');
Regards
Harish

View solution in original post

6 REPLIES 6

Sumanth16
Kilo Patron
 

 

       
 

 

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

var cabdate = new GlideDateTime('current.opened_at');
var fd = new GlideDateTime(cabdate);
var dateToPrint = fd.getDate();
var get = dateToPrint.getByFormat('MM-dd-yyyy'); 
template.print(get);
        template.print('<p>Opened:</p> ' + get);
})(current, template, email, email_action, event);


In notification body-------------
${mail_script:mailscriptname}

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda

 

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

 

 

Please hit like button if my suggestion has helped you in any way.
Please mark correct if my response has solved your query.

Cheers,
Mohammed Basheer Ahmed.

Thank you, I did have the word Opened in the body of the notification.  I thought I had removed it, bur I missed it apparently or didn't save it when i did remove it.  Have a nice day.

Harish KM
Kilo Patron
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>');
Regards
Harish