cancel
Showing results for 
Search instead for 
Did you mean: 
Pstork1

Running a Recurrence Flow on Weekdays Only

Recurrence.pngRecurrence Triggers are essential for a wide variety of scenarios.  They can be used to run a flow on a specific date and time.  Or they can be used to run a flow on a recurring schedule, like once a day or once a month.  They can even be used in situations where  a process needs to run longer than the 30 day timeout limit on flows.

But what if your recurring schedule has exceptions.  For example, you might want to run it on the first Monday of each month or only on weekdays.  How can we use the recurrence trigger to handle these more complicated scenarios?

One possible solution is to trigger the flow on a simple schedule, like daily, and then test to see if its the right day.  If it is, proceed with the flow, but if its not just exit.  This does work, but it consumes a lot of flow runs that are unnecessary.  Not only is this inefficient it may cause an issue with the limits on API calls in a 24 hour period.  It would be much better if we could take these conditions into account BEFORE the flow triggers.  But we can’t always reach that level of granularity in the trigger configuration itself. But we can if we use the trigger conditions available under settings.

Let’s look at a specific scenario.  I want this flow to trigger on each workday of the month. I start out by creating a flow with a trigger set to fire once a day.  This will create a flow that runs everyday of the month.  So far the trigger will look like this.

RecurrenceTrigger.png

Next I need an appropriate filter that will limit the trigger to only fire on Monday thru Friday.  If you aren’t familiar with how to write that filter I suggest using a ‘Filter array’ action to put it together.  After adding a ‘Filter array’ action to your flow fill in the left side of the comparison with the following formula:

dayOfWeek(utcNow())

That will take the current date and convert it to a number for the day of the week.  Monday = 1, Tuesday = 2, etc. Now finish the condition by choosing ‘is less than or equal to’ in the middle and enter ‘5’ on the right.  We haven’t filled in the Array to filter, but since all we want is the formula that’s OK.  We’ll be deleting this action after we copy the formula.  Your action should now look like this.

filter array.png

Now comes the trick that makes this worthwhile.  Click on the ‘Edit in advanced mode’ link. The action will now look like the following.

filter array advanced.png

The formula we need is the one highlighted in yellow.  Copy that formula to your clipboard and delete the ‘Filter array’ action.  Our finished flow doesn’t actually use it.  Now open the settings dialog for the recurrence trigger using the ellipses (…) menu on the trigger. Click the + Add link under Trigger Conditions and paste the formula you copied into the textbox that appears.  Your Settings should now look like this.

Settings.png

You can now click Done and your flow trigger each day if it is a Monday through Friday.  It will not trigger on Saturday, day 6, or Sunday, day 7. Using trigger conditions you can fine tune the schedule of your recurrence trigger to only fire when you want it to.

Comments

Microsoft documentation states that the DayOfWeek function returns a value from 0 to 6, with 0 being Sunday, so a singular "less than or equal to 5" statement wouldn't be enough for this to work. Is there a way to incorporate both conditions into a single statement as the benefit of this method is obvious 🙂

 

Edit: oh, you can just add a second condition 🙃

For those who come here and just want the simple weekday formulas this should hopefully be enough:

 

@greaterOrEquals(dayOfWeek(utcNow()), 1)

@lessOrEquals(dayOfWeek(utcNow()), 5)

 

Now I will hopefully not be accused of disturbing people on the weekends.

If I run flow in EST time zone will it cover day light saving time ?

For those finding this article through google there's a much simpler way as laid out here: https://www.ameyholden.com/articles/schedule-power-automate-flows-weekdays-only.

 

Set the frequency to Week and then you can just straight select the days of the week from the 'On these days' dropdown.

Great find @severynm. I really do hope that solution was not in place when these previous alternatives were discussed.

 

Can just agree that picking Weekly and the multiple weekdays is a much better option!

 

 

@not(or(equals(dayOfWeek(utcNow()), 0), equals(dayOfWeek(utcNow()), 6)))

One can use the above in trigger conditions to run any flow only on weekdays

@Pstork1 you may want to update this slightly with the new Environment.

About the Author
  • Experienced Consultant with a demonstrated history of working in the information technology and services industry. Skilled in Office 365, Azure, SharePoint Online, PowerShell, Nintex, K2, SharePoint Designer workflow automation, PowerApps, Microsoft Flow, PowerShell, Active Directory, Operating Systems, Networking, and JavaScript. Strong consulting professional with a Bachelor of Engineering (B.E.) focused in Information Technology from Mumbai University.
  • I am a Microsoft Business Applications MVP and a Senior Manager at EY. I am a technology enthusiast and problem solver. I work/speak/blog/Vlog on Microsoft technology, including Office 365, Power Apps, Power Automate, SharePoint, and Teams Etc. I am helping global clients on Power Platform adoption and empowering them with Power Platform possibilities, capabilities, and easiness. I am a leader of the Houston Power Platform User Group and Power Automate community superuser. I love traveling , exploring new places, and meeting people from different cultures.
  • Read more about me and my achievements at: https://ganeshsanapblogs.wordpress.com/about MCT | SharePoint, Microsoft 365 and Power Platform Consultant | Contributor on SharePoint StackExchange, MSFT Techcommunity
  • Encodian Owner / Founder - Ex Microsoft Consulting Services - Architect / Developer - 20 years in SharePoint - PowerPlatform Fan
  • Founder of SKILLFUL SARDINE, a company focused on productivity and the Power Platform. You can find me on LinkedIn: https://linkedin.com/in/manueltgomes and twitter http://twitter.com/manueltgomes. I also write at https://www.manueltgomes.com, so if you want some Power Automate, SharePoint or Power Apps content I'm your guy 🙂
  • I am the Owner/Principal Architect at Don't Pa..Panic Consulting. I've been working in the information technology industry for over 30 years, and have played key roles in several enterprise SharePoint architectural design review, Intranet deployment, application development, and migration projects. I've been a Microsoft Most Valuable Professional (MVP) 15 consecutive years and am also a Microsoft Certified SharePoint Masters (MCSM) since 2013.
  • Big fan of Power Platform technologies and implemented many solutions.
  • Passionate #Programmer #SharePoint #SPFx #M365 #Power Platform| Microsoft MVP | SharePoint StackOverflow, Github, PnP contributor
  • Web site – https://kamdaryash.wordpress.com Youtube channel - https://www.youtube.com/channel/UCM149rFkLNgerSvgDVeYTZQ/