Monday, June 20, 2016

Sitecore "Schedule" Field in Depth

All Sitecore Schedule tasks have Schedule field that correspond for setting up interval of running tasks.
It is quite intuitive, especially when you will read description. It has format {0}|{1}|{2}|{3}.
Where:
  1. Date stamp when task running should be started. 
  2. Date stamp when task running should be ended.
  3. Days of week when task should be run.
  4. Time span interval how often task should be run.
All of components of this string have clear format, except third. Let's look  how it works. Under hood third component is cast to DayOfWeek enum.

public enum DaysOfWeek
{
 None = 0,
 Sunday = 1,
 Monday = 2,
 Tuesday = 4,
 Wednesday = 8,
 Thursday = 16,
 Friday = 32,
 Saturday = 64
}

And value that you should indicate days of week when schedule should be run is sum of this components. E.g.: task that should be run on Monday and Thursday. 2 +16 = 18. (indeed there is binary operation OR of 100 and 100000 values, but you can use decimal system for simplifying ).

It could take some time to get this value in head when you don't work with schedule field day to day. That is why I prepared script that will calculate this value for you:


P.S. Another good option is Sitecore Shell Wax shared source module. If Content Managers do changing of scheduled tasks day to day - it is better option to use this module.