How to display yesterday date in scheduled report subject line and body text?

Bala13
Kilo Guru

Hi,

How can i get the yesterday date in subject line and body text of Scheduled report ?

And also, is it possible to include specific DL's in CC of scheduled reports?

 

Please help me on this

1 ACCEPTED SOLUTION

Hi,

this worked well for me

var gdt = new GlideDateTime();
gdt.addDaysUTC(-1);

var dt = new GlideDate();
dt.setValue(gdt.getDate());

gs.info('Actual date->' + dt);

var year = dt.getByFormat('YYYY');

var day = dt.getByFormat('dd');

var month = dt.getByFormat('MMMM');

var ordinal = dateOrdinal(day);

function dateOrdinal(d) {
	return d+(31==d||21==d||1==d?"st":22==d||2==d?"nd":23==d||3==d?"rd":"th");
}


var finalStr = month + ' ' + ordinal + ' ' + year;

gs.info('Final date->' + finalStr);

Output:

[0:00:00.064] Script completed in scope global: script


Script execution history and recovery available here


*** Script: Actual date->2021-04-15
*** Script: Final date->April 15th 2021

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

9 REPLIES 9

Bhawanjit Sing2
Mega Guru

Hi

You can add a notification email script in the message body.

So you can take the advantage of all the objects available inside that.

//For yesterdays date
var gdt = new GlideDateTime();
gdt.add(-1);

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

As mentioned you can include email script in email body

Adding to his point here is the email script

var gdt = new GlideDateTime();
gdt.addDaysUTC(-1);
template.print(gdt.getDate());

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur, how can i get the date format like April 15th 2021?

Hi,

you need to do manipulation there

check this

https://stackoverflow.com/questions/15397372/javascript-new-date-ordinal-st-nd-rd-th

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader