Current Date in Email Notification

Sandy7
Tera Expert

I have an email notification that calls several mail scripts. 

I am looking to add the current date to the subject of the email -- so "Notification for - Current Date"

It seems like there should be a way to do this but I can't figure it out. Has anyone done this?

Thanks, 

Sandy

1 ACCEPTED SOLUTION

Can you try below then,


(function runMailScript(current, template, email, email_action, event) {

var gDateTime=new GlideDateTime();
var gDate = new GlideDateTime().getDate();
var gFormat=gDate.getByFormat('EEEE, MMMM dd');
var gt = (new GlideDateTime()).getLocalTime().getByFormat('hh:mm a');
//gs.print(gt);
//var TFormat=gt.getByFormat('HH:mm');
	var FinalFormat=gFormat+' '+gt;
//gs.print(FinalFormat);
template.print(FinalFormat);


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

 

Output as desired.

find_real_file.png

View solution in original post

18 REPLIES 18

Actually each time I run this, everything is perfect except the time keeps saying 20:00..

In that case replace

var TFormat=gt.getByFormat('HH:mm');

with

var TFormat=gt.getByFormat('HH:mm aa');

 

find_real_file.png

 

Also, if above answers helped you can mark it Helpful as well.

Thank you. That adds PM at the end, but each time I run it, the time always says 20:00 rather than update to the current time. I am not sure why..

I really appreciate your help

Can you try below then,


(function runMailScript(current, template, email, email_action, event) {

var gDateTime=new GlideDateTime();
var gDate = new GlideDateTime().getDate();
var gFormat=gDate.getByFormat('EEEE, MMMM dd');
var gt = (new GlideDateTime()).getLocalTime().getByFormat('hh:mm a');
//gs.print(gt);
//var TFormat=gt.getByFormat('HH:mm');
	var FinalFormat=gFormat+' '+gt;
//gs.print(FinalFormat);
template.print(FinalFormat);


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

 

Output as desired.

find_real_file.png

This is great - I can't thank you enough!