- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2021 11:47 PM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2021 04:47 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2021 03:47 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2021 03:48 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2021 04:33 AM
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"));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2021 04:47 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2023 02:24 PM
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