Here is a little helper I use when creating flows that I only want running during business hours only.
Let's say we generate an hourly email that goes to shared mailbox. There are times when this email is pointless after 6pm or before 8am (per say). There are times when there is no need to have this email outwith Monday to Friday so here is an easy way to handle that.
Retrun true if after 8am but before 5pm
@and(greaterOrEquals(formatDateTime(utcnow(),'HH:mm'), '''08:00'''), lessOrEquals(formatDateTime(utcnow(),'HH:mm'), '''17:00'''))
Return true if not Saturday or Sunday
@or(not(equals(formatDateTime(utcnow(),'dddd'), '''Saturday''')), not(equals(formatDateTime(utcnow(),'dddd'), '''Sunday''')))
When either of the above returns false I like to the "Terminate" action to complete Flow as a success.
Both of the above conditions have the same "Terminate" action with in. So once you satisfy the conditions the Flow can now push on and do something useful.
If this post helps you, please help the community by clicking thumbs up.
Hi @AlanPs1 , thanks for sharing this. Very helpful.
Does this mean the flow runs every hour within those business hours? The interval attribute suggests it runs once every hour between 8am to 5pm.
I'm looking to achieve something similar but want to leave the flow snoozing outside business hours and keep it running continuously between 8am to 5pm.
Hi @DynamicGanesh , thank you for your reply.
You're right, it runs every hour on the hour. The start time helps it run on the hour. This doesn't snooze or delay but for example, if it runs outwith the hours of 8am to 5pm the Flow terminates as a success and does no more as it is aware it is out of hours.
Adding a delay could be a neat enhancement actually so it'd be nice to see how you customise this to acheive that. I posted this as I used the method to generate an hourly report of live O365 service health issues and there was no need to have the update arrive in a shared mailbox outwith these hours as there was no-one there to read it at those times. It finished at 5pm and started again at 8am the next morning.
If you find my posts helpful, please mark with thumbs up
Any questions, just ask.
@AlanPs1 Thanks Alan, appreciate your quick response. I'll have to tweak my approach a bit now. The scenario we have is:
We've got a flow running on SQL row update trigger for a SQL database table to send emails based on certain SQL field values/conditions. It runs perfectly fine but now we also have added a stored procedure (running overnight outside of business hours) which is also updating this table.
We do not want the flow to trigger for these updates (as there will be thousands of unncessary flow runs) which is why I was curious about your solution to ignore the SQL updates occurring outside of business hours.
The real limitation with Flow is conditionally triggering a flow based on update of certain attributes/fields. I'll post here if I'm able to solve it.
@AlanPs1 I'm considering a Flow Management or Microsoft Flow for Admin connector action (plus recurrence/timer) to achieve this. Both offer options to control other flows running within an environment.
First off, thanks for this @AlanPs1 ! Just the logic I was looking for.
I took it one step further by adding the logic to the Recurrence trigger criteria rather than a condition statement, so the flow doesn't even trigger outside the business hours (saving Flow runs & keeping the run log cleaner).
I want mine to run on the weekends as well as weekdays (just 8-5), but you could also combine the two queries just by adding the "or" statement as a third condition to the "and".
@and(greaterOrEquals(formatDateTime(utcnow(),'HH:mm'), '''08:00'''), lessOrEquals(formatDateTime(utcnow(),'HH:mm'), '''17:00'''),or(not(equals(formatDateTime(utcnow(),'dddd'), '''Saturday''')), not(equals(formatDateTime(utcnow(),'dddd'), '''Sunday'''))))
Fill out a quick form to claim your user group badge now!
We've given our badges an overhaul and also added some brand new ones!
Learn how to build the business apps that you need.
Find out where you can attend!
Watch & learn from the Power Automate Community Video Gallery!