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

Jaspal Singh
Mega Patron
Mega Patron

Hi Sandy,

 

Try using below in subject with same format for Scheduled Reports.

javascript: 'Your Text here '+gs.nowDateTime().split(' ')[0]

 

For normal notifications

You need to create a mailscript from System Notificaiton >> Email >> Notification Email Script named getdatetimevalue with below code.

var dateis =  gs.nowDateTime().split(' ')[1];
email.setSubject("your text for report"+dateis);

& then call it in your notification body as below

${mail_script:getdatetimevalue}

Thanks - this is close but for some reason it's only giving the time.. not the date. Any ideas?

 

Try using below & confirm (should give you date & time). Also, can you kindly confirm the DateTime format you use.

var dateis =  gs.nowDateTime();
email.setSubject("your text for report"+dateis);

Did the above worked?