My Job should Execute on every last date of the month(Excluding Sat, Sun and Holiday)

Hello All,

I have to Run One JOB(Timer) Which should be executed on Every Last date of the Month.

But if there is a Saturday or Sunday or any Holiday it should take pervious data to Execute the that JOB.

For E.G :-   31-Oct-21 is a Sunday, then we have to move pervious date i.e Saturday, 30-Oct-21 (Job should not execute) move pervious i.e 29-Oct-21( if that is Holiday then it should take pervious date i.e 28-Oct-21)

So our Job should Execute on 28-Oct-21..


I have Already implement the below logic but need further logic to avoid weekend and Holidays to be implemented.


Can anyone help me on this.


Thanks

Hi,

You can take a look at this solution.

There is an idea to write a function to check weekend or holidays.

Cheers,

Khuong

Hi,

First of all, you need a logic to get which day to run this job, then compare current day with that day, if it is the same day, then run, else ignore. 

And the logic to get the run day of one month, is to do a circle from the last day of this month, check whether it is the weekend or holiday, if yes, then go to the preview day, if not, then return the day.

Hi,

so I think you already get the part of the timer running every day, but not actually doing anything unless it's the right day.

As to how to determine if it's the right day, the difficult part is knowing what is considered a holiday, as this can depend on location and industry or even company.

1° if you have to maintain your own list of what is considered a holiday

I would say, don't bother maintaining  a list of holidays, just maintain a list of run days.  Then your logic can just be  an aggregate to read if current day is a run day, if not, don't do anything.


2° if you can make use of some service within your company / industry / country to determine holidays

In that case, you could implement a loop, starting off the date as the last day of the current month.  And then in the loop

  • check if it's not a weekend day
  • check if it's not a holiday day (how that is to be done, depends on where and how that information is available)

after each check, if it fails, substract one day and loop again.  If all checks pass, you've got your date.  Then just check if current date is that date to know if you need to run today.


Dorine

Hello,

Step 1: Calculate the Last date of the Month

Step 2: Check whether it falls on Sunday or Saturday

Step 3: As mentioned in the previous comment by Dorine, you have to maintain the list of Holidays and check if the calculated last day falls on the same, if so then by using AddDays(LastDay,-1) recalculate the last day and check the holiday list again.

Step 4: Using the Schedule runtime property of the timer assign the last day value.

The above logic has to be placed at the end of timer action to schedule the next run. But for the First time, I guess you can schedule it using the servicecenter. Using this approach you don't have to run the timer on daily basis.

I have attached the sample OML for your reference. Let us know if this solution helps you.

Happy Coding.

Mathavan. V

TimerTest.oml

Thanks Maddy for your reply, Will check and let you know on this...

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.