Cron Expression: Last day of Month, Except Friday

I’m working on the UIpath Orchestrator where I need to put a custom scheduler for a job, here is the cron expression which I written 0 0 5 L * ? * , it works fine and run’s every last day of the month but now I want to change this expression that will work only if the last working day is not Friday.

can you try 0 0 L * 0-4,6

the 0-4 should be sunday to thursday, then 6 is saturday, skipping friday

this expression is not valid in syntax (PFA), although you can verify your expression over this website:

http://www.cronmaker.com/

Hi @Hafizhaseeb_Amjad ,

Try below Cron expression
0 0 0 L * SUN,MON,TUE,THU,SAT

Regards,
Arivu

same error, Invalid cron expression syntax.
you can also verify your cron expression syntax over this website. http://www.cronmaker.com/

Hi @Hafizhaseeb_Amjad ,
In cron expression i guess we can’t use day of the month and day of the week at the same time.

Regards,
Arivu

if what @arivu96 says it true, this will limit being able to do this.

a dirty way of doing it may just be to let it run on the friday, but in the automation itself have an if statement right at the beginning with date.today.dayoftheweek.tolower = “friday” then dont continue if it is friday. its not an ideal solution but would work around the CRON issue

yeah that’s exactly what I conclude till now.

at last there is always a way to do the things but what if we are strictly bind to the orchestrator to perform this cron expression, there should be a solution too through the expression.

UiPath Orchestrator depends on Quartz .NET Framework so you are limited to what it supports for your cron expression.

This is true, from the Quartz documentation, you’ll find this note in the Cron Trigger section.

Notes

  • Support for specifying both a day-of-week and a day-of-month value is not complete (you must currently use the ‘?’ character in one of these fields).

I would also encourage yourself and other to search the forums. There are many already posted topics and solutions that cover similar scenarios. As I see topics that are not categorized or tagged, I’ve been doing so and can find them by searching Tags:Cron, or simple Cron in the topic titles. Chances are a particular scenario has been asked before, but perhaps just not for your specific days.


As for alternatives, as @Djh pointed out, you can embed that logic into your init of the process to check prevent it from continuing to run if a given criteria is met. I would make this a configuration so you can adjust it as needed without changing your workflow.

Another potential option is to leverage the Non-Working Days Calendars, it’s has it’s pros and cons, I’ve only used it for one instance and adds some management overhead, which in my case I’ve forecasted out a couple years… and to truly make it useful would probably need to extend its functionality to be more granular for example could use an external service to manage the Non-Working Days or Enablement/Disablement of the Trigger itself through the API

Create two separate triggers with the below expressions and this might work.

0 * * 1-27 * ?
Every minute, between day 1 and 27 of the month

0 * * 28-31 * SUN,MON,TUE,WED,THU,SAT
Every minute, between day 28 and 31 of the month, only on Sunday, Monday, Tuesday, Wednesday, Thursday, and Saturday

Not an expert on this, Hope this helps you.

Hi @Hafizhaseeb_Amjad

You will be able to achieve using a cron expression for the last day of the month.

You will need to create a Non-Working days calendar for all the Friday’s which are on the last day of the month.

Hopefully this helps

Cheers

Steve

Hi @Jerry1, As noted above @Hafizhaseeb_Amjad is looking for the Last day of the month only when it does not fall on a Friday.

As well this will not work as mentioned above, you cannot designate both Day of Week AND Day of Month within the same Cron Expression. This is a limitation of the Quartz.NET Framework.

1 Like