Schedule report to run on last Friday of every month

karthikbabu
Giga Expert

Hi friends,

 

I am not a reporting expert. Need help in writing a schedule job for a report to send an email on last friday of every month.

I went to report and then click on schedule, under Run selected monthly and it shows day of the month. Please suggest on how to write a schedule job to send an email on last friday of every month.

 

Thanks in advance,

Karthik

1 ACCEPTED SOLUTION

Marcello Correa
ServiceNow Employee
ServiceNow Employee

More details on my solution... Use the script below in your condition:

function isLastWeekOfMonth() {
	var report_date = new GlideDateTime();
	var days_in_month = report_date.getDaysInMonthUTC();
	var day_of_month = report_date.getDayOfMonthUTC();
	if (day_of_month >= days_in_month - 6) {
		return true;
	} else {
		return false;
	}	
}

isLastWeekOfMonth();

More info can be found below:

Scheduled Reports - Condition Script

 

View solution in original post

13 REPLIES 13

Michael Lee1
Tera Expert

I would look into combining a getDayOfWeek() method with a getDaysinMonth() method and then writing a condition script that makes sure the day of the week = 5 (Friday), but that there are less than 7 days left in the month. That will let you know that it's the last Friday of the month and will be dynamic for the changing amount of days in each month. 

In your regular script you can workout what you want to happen with firing your email with your report. 

Hi Michael,

 

As per your saying, does the script should look like this?

getDayOfMonth > 25 && getDayOfMonth <=31&& getDayOfWeek() == 5

Marcello Correa
ServiceNow Employee
ServiceNow Employee

More details on my solution... Use the script below in your condition:

function isLastWeekOfMonth() {
	var report_date = new GlideDateTime();
	var days_in_month = report_date.getDaysInMonthUTC();
	var day_of_month = report_date.getDayOfMonthUTC();
	if (day_of_month >= days_in_month - 6) {
		return true;
	} else {
		return false;
	}	
}

isLastWeekOfMonth();

More info can be found below:

Scheduled Reports - Condition Script

 

Hi Marcello,

 

Thanks for responding.

Your script runs if it is the last week of the month. Does it checks last friday of the month?

Thank you.

What if this below condition works? Please let me know if this return the last friday of every month.

getDayOfMonth > 22 && getDayOfMonth <=31 && getDayOfWeek() == 5