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

Could you please help me how to do that?

var gd = new GlideDate();

gs.print(gd.getByFormat("MMMM"));

 

i used this but i am not getting correct data

Hi,

like this

var gdt = new GlideDateTime();

gdt.addDaysUTC(-1);

var gd = new GlideDate();

gd.setValue(gdt.getDate());

gs.info(gd.getByFormat("MMMM"));

I hope I have answered your original question

Please mark response as correct and close the thread.

Regards
Ankur

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

Hi Ankur,

This is printing only April, how to get both month, year and date?

Tried like ths, but it is printing like 15/04/2021

But i need like April 15th 2021

 

 

var gdt = new GlideDateTime();

gdt.addDaysUTC(-1);

 

var gd = new GlideDate();

gd.setValue(gdt.getDate());

gs.print(gd.getByFormat("dd/MM/YYYY"));

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

Ebrunken
Tera Contributor

I've been trying to get this to work myself as this is exactly what I'm looking for.   Is this supposed to be created in System>Client Scripts, or Notification Email Scripts?  I tried working through the body as well as via source code but that just outputs the code.

 

Thanks,


Evan