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

Hi - this is what I used to get it to work - template.print(gs.nowDateTime());

 

However, now I am trying to change the format to be Tuesday, May 18... the code above returns "2020-05-18" and it also includes the time.. do you have any idea if I am able to convert the time format?

 

Thanks

Hi Sandy,

 

Try using below.

(function runMailScript(current, template, email, email_action, event) {
var gDTis = gs.nowDateTime();
    var gDT = new GlideDateTime(gDTis);
    var gDate = gDT.getDate();
    var gDTFormat = gDate.getByFormat("MMMMMMMM d");
    var gDayis = gDT.getDayOfWeekLocalTime();
    var weekday = new Array(7);
    weekday[0] = "Sunday";
    weekday[1] = "Monday";
    weekday[2] = "Tuesday";
    weekday[3] = "Wednesday";
    weekday[4] = "Thursday";
    weekday[5] = "Friday";
    weekday[6] = "Saturday";

    var n = weekday[gDT.getDayOfWeekLocalTime()];
    var finalis = n + ',' + gDTFormat;
    template.print(finalis);

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

 

Output as below,

find_real_file.png

That's great! Now I am just trying to figure out how to get the time in there - the customer is asking for the current time to be added - Tuesday May 19, 2:14PM... would you be able to help me one last time 🙂 Thank you so much!

Hi Sandy,

 

Find below the simplified version.

(function runMailScript(current, template, email, email_action, event) {
var gDate = new GlideDateTime().getDate();
var gFormat=gDate.getByFormat('EEEE, MMMM dd');
var gt = gDate.getLocalTime();
var TFormat=gt.getByFormat('HH:mm');
	var FinalFormat=gFormat+' '+TFormat;
template.print(FinalFormat);
	//email.setSubject("your text for report    " + FinalFormat);

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

 

Output:

find_real_file.png

THat is perfect! thank you so much for your help!!!!