The easiest way would be to run on the first day of a month and send results for a previous month.
Another way you can do it is to create a schedule which runs 9:00 am to 9:30 am every day (or 28-31) and checks if this is a last day of a month before doing anything.
Schedule is limited to Max String length, so you can also generate a very long schedule once. For example this code would produce a schedule for the next 10 years:
/// date - start date. Must be the last day of the month.
/// months - how many months to generate
ClassMethod Test(date = "2024-09-30", months = 120)
{
while $i(months,-1)>=0 {
set year = $system.SQL.DATEPART("year", date)
set month = $tr($j($system.SQL.DATEPART("month", date), 2), " ", 0)
set day = $system.SQL.DATEPART("day", date)
write $$$FormatText("START:%1-%2-%3T09:00:00,STOP:%1-%2-%3T09:30:00,", year, month, day)
set date = $system.SQL.DATEADD("day", -1, $system.SQL.DATEADD("month", 1, $system.SQL.DATEADD("day", 1, date)))
}
}Schedule
If you're okay with February 28th for leap years a schedule can be simplified to 12 entries with * in the year.
If all of the above is not an option create a separate Business Service which runs on a first day of a month, calculates last day of a month and sets a correct schedule for BO.
- Log in to post comments