How to schedule a report of every 1st of month and last of month

Atik
Tera Contributor

Hello Everyone,

I have requirement where user is requesting to schedule a report on monthly basis addition to that his request is to report should trigger every 1st and last of month.

 

For example, If month is of 31st days then report should trigger on 1st and 31st.

 

Could someone help me how I can achieve this.

Thanks is advance,

Atik Bagwan

4 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

@Atik 

you can have 2 scheduled jobs

1) running on 1st day of month

2) running on last day Set the run date to the 31st at 00:00:00 will run the job on the last day of every month at 00:00:00 only

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Atik 

 

This is not possible in one schedule since the dates are different. You can schedule the same report twice—once for the 1st and once for the 31st—and send the reports. This is the best and easiest way.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

View solution in original post

Pratiksha Lang1
Kilo Sage

@Atik You can try this in 2 ways:

You can create two different scheduled jobs that run on the 1st and last day of the month.

Step 1: Create a Scheduled Report for the 1st of the Month

  • Go to Scheduled Reports.
  • Click New to create a new scheduled report.
  • Fill in the Report field to select the report you want to schedule, then under schedule : 
    • Choose Run Monthly.
    • Set the schedule to run on the 1st day of the month.
  • Configure the Time to when you want the report to be sent.
  • Select the recipients and any other settings as required.
  • Save the scheduled report.

Similarly, you can do it for last day of the month for which create another scheduled report

OR:

 

Write a scheduled script execution and set to run for daily and write the code below:

 

(function executeScheduledScript() {
var today = new GlideDateTime();
var dayOfMonth = today.getDayOfMonth(); 
var lastDayOfMonth = new GlideDateTime();
lastDayOfMonth.addDaysUTC(-1); 
lastDayOfMonth.setDisplayValue(lastDayOfMonth.getYear() + "-" + (lastDayOfMonth.getMonth() + 1) + "-" + lastDayOfMonth.getDayOfMonth());

if (dayOfMonth === 1 || dayOfMonth === lastDayOfMonth.getDayOfMonth()) {
var report = new GlideRecord('sys_report');
report.addQuery('name', 'Your Report Name'); 
report.query();
if (report.next()) {
var reportUtil = new GlideReportUtil();
reportUtil.runReport(report.sys_id);
}
}
})();

View solution in original post

AndersBGS
Tera Patron
Tera Patron

Hi @Atik ,

 

As other have mentioned, best solution is to make two different schedules. One for the fist day and 1 for the last day. This can be done OOTB without scripting. 

 

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@Atik 

you can have 2 scheduled jobs

1) running on 1st day of month

2) running on last day Set the run date to the 31st at 00:00:00 will run the job on the last day of every month at 00:00:00 only

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Atik 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Atik 

 

This is not possible in one schedule since the dates are different. You can schedule the same report twice—once for the 1st and once for the 31st—and send the reports. This is the best and easiest way.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Pratiksha Lang1
Kilo Sage

@Atik You can try this in 2 ways:

You can create two different scheduled jobs that run on the 1st and last day of the month.

Step 1: Create a Scheduled Report for the 1st of the Month

  • Go to Scheduled Reports.
  • Click New to create a new scheduled report.
  • Fill in the Report field to select the report you want to schedule, then under schedule : 
    • Choose Run Monthly.
    • Set the schedule to run on the 1st day of the month.
  • Configure the Time to when you want the report to be sent.
  • Select the recipients and any other settings as required.
  • Save the scheduled report.

Similarly, you can do it for last day of the month for which create another scheduled report

OR:

 

Write a scheduled script execution and set to run for daily and write the code below:

 

(function executeScheduledScript() {
var today = new GlideDateTime();
var dayOfMonth = today.getDayOfMonth(); 
var lastDayOfMonth = new GlideDateTime();
lastDayOfMonth.addDaysUTC(-1); 
lastDayOfMonth.setDisplayValue(lastDayOfMonth.getYear() + "-" + (lastDayOfMonth.getMonth() + 1) + "-" + lastDayOfMonth.getDayOfMonth());

if (dayOfMonth === 1 || dayOfMonth === lastDayOfMonth.getDayOfMonth()) {
var report = new GlideRecord('sys_report');
report.addQuery('name', 'Your Report Name'); 
report.query();
if (report.next()) {
var reportUtil = new GlideReportUtil();
reportUtil.runReport(report.sys_id);
}
}
})();