Solved

Cron Expression for Bi-Weekly

  • 7 October 2020
  • 4 replies
  • 254 views

Userlevel 7
Badge +1

I’m looking for a way to build a Cron expression that would allow a few of my Rules to run every two weeks in order to keep up with my ProServ team’s 2-week cycle. Running it every 15 days with 0 0 12 1/15 * ? unfortunately does not do the trick, and I don’t want to miss adjustments by changing it every month. 

Any ideas or suggestions? Any way I can incorporate the Rule Date into the actual Rule logic? 

icon

Best answer by jean.nairon 8 October 2020, 20:05

View original

4 replies

Userlevel 3
Badge

“Any way I can incorporate the Rule Date into the actual Rule logic? “
 -- In bionic rule’s transformation task you have the rule date available (Formula field → Date fomulas). Is this what you are looking for?

And what all dates are you looking for the rule to run on and why that cron expression won’t work?

Userlevel 7
Badge +1

@gunjanm unfortunately the cron expression logic does not have an instruction set for every two weeks (every 14 days). Is there some other system event that you could use as a trigger for the rule like presence of a field in an object or something? 

Userlevel 7
Badge +2

This might be a bigger work around than you would want but you could potentially use a table to track when you want this rule to run. I haven’t tested this out though.

For this trick, you would need to run your rule every Monday. And the key is your data queries will filter for data if the Run Date = Today. So each Monday it will run, but it will only find data that matches every 2 weeks. 

 

First step, I would create a table to host your run dates. Use Excel to create a list of all the dates. You can use a formula in excel to calculate Start Date + 14 day. So in the end you would have, 

  • 10/05/2020
  • 10/19/2020
  • 11/02/2020
  • Etc

 

In your rule, I would add a filter somewhere in your queries to search for the date. If today = run date, then you query provides your expected results. If Today does not equal Run Date, the query would provide zero results, thus your rule would run nothing on the Monday’s where this date does not match. 

On your schedule, you would set the rule to run every Monday. When you look at your rule results, you should end up with a run that works on the correct Monday, and then one that fires nothing on the following Monday. 

Userlevel 7
Badge +1

@jean.nairon I think I’m gonna try this! And perhaps also using odd/even weeks right in the Rule. Let’s chat about this on our beer call tomorrow… :) 

Reply