I recently got a request for a workflow to run on the 1st calendar day of the month or first business day if the 1st fell on a weekend. I first though that it wasn't possible to do with the native scheduling and PowerShell was needed. After I wrote up a Posh script to do the heavy lifting, it dawned on me how to use the native schedule activity. It's not as straight forward as using the script, but does work.
Orchestrator's built-in schedule activity supports two options:
1) Specifying the calendar day(s) of the month to run
2) Specifying the week day to run
Here is the "main" runbook for the schedule that will invoke the rest of the workflow. It requires four different schedule activities to accomplish the logic. Each of the following links (green) have the logic "confirms to schedule equal to true".
Here is the PowerShell script to accomplish the same schedule result. The "$Success" variable would be in the Published Data to use in the link logic to continue or not if Success equals true.
$DayOfWeek = [DateTime]::Now.DayOfWeek
$DayOfMonth = [DateTime]::Now.Day
If ( (($dayOfMonth -eq 1) -and ($dayOfWeek -ge [DayOfWeek]::Monday) -and ($dayOfWeek -le [DayOfWeek]::Friday)) -or ((($dayOfMonth -eq 2) -or ($dayOfMonth -eq 3)) -and ($dayOfWeek -eq [DayOfWeek]::Monday)) )
{
$Success = $true
}
Else {
$Success = $false
}
GREAT, i alreeady was looking for something like this :)
ReplyDeleteAwesome! Thank you! Saved a lot of time!
ReplyDeleteSo, this works but will first business day on the 2nd or 3rd always be on a Monday?
ReplyDeleteIf Saturday is the 1st, Monday would be the 3rd.
DeleteIf Sunday is the 1st, Monday would be the 2nd.