cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
gosubtle
Level: Powered On

Recurrence - Running a flow during business hours on business days

Hi all, i figured i would share this with the community in case it would help out someone as other posts here helped me figure out some stuff for my first production flow successfully running.

 

It's super simple but a bit crude (you have to either readjust to daylights savings time or widen the range) and doesn't use any calendars from your company at least as written.  Follow these simple steps but please read the full post as there is a drawback with using this approach.

 

1. Create a condition step.

2. On the "no" branch, add the action "Terminate" (which should be easier to search for).

3. Leave the "yes" branch blank and put any actions after it.

4. In the condition step, click on "edit in advanced mode" and enter the following:

 

@and(
  or(equals(dayofweek(addhours(utcnow(), -6)), 1),
    or(equals(dayofweek(addhours(utcnow(), -6)), 2),
      or(equals(dayofweek(addhours(utcnow(), -6)), 3),
        or(equals(dayofweek(addhours(utcnow(), -6)), 4),
           equals(dayofweek(addhours(utcnow(), -6)), 5))
      )
    )
  ),
  and(greaterOrEquals(int(formatDateTime(addhours(utcnow(), -6),'%H')),8),
      lessOrEquals(int(formatDateTime(addhours(utcnow(), -6),'%H')),19))
)

5.  Adjust the above -6 (which is currently central time), and the hours [the 8 and 19 at the bottom expression].  The times are in 24 hour notation.

 

6.  Add another "or" clause in the dayofweek area if you need to add Saturday.  The 1-5 is M-F.  Sunday is 0 and Saturday is 6.

 

Now to the two critical details.  With the workflow written like this, you will want to kick it off as a recurrence.  You can set it to run just daily (day for unit and 1 for each day) but this is really written as is for hour increments.  I myself set it to every 2 hours.  The problem with having it run every hour or even two, it does start to eat at your free flow quota pretty quickly.  Here is the approximate number of flows from your quota per month if you need to decide how important it is.

 

Every hour: 720

Every two hours: 360

Every three hours: 240

Every four hours: 180

Every eight hours: 90

 

Keep in mind as you go to more time between, depending on what you have your start time set to, you can actually start missing frequency pretty badly.  Also, I highly recommend for most people, set a start time in the advanced recurrence to start at an off hour.  So start it at 2017-05-05T20:10:00Z instead of 2017-05-05T20:00:00Z for instance.

 

I hope this helps someone, good luck on your flow adventures.

 

 

 

 

 

6 REPLIES 6
Community Support Team
Community Support Team

Re: Recurrence - Running a flow during business hours on business days

Hi @gosubtle,

 

Thanks for sharing!

I wrote a similar condition to check the working hours, see:

How to tell if the current time is within the Business hours

And some notes for using it.

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
timr
Level: Powered On

Re: Recurrence - Running a flow during business hours on business days

Hi @v-micsh-msft,

 

I'm unable to access your link on telling if it is business hours. Can you assist as this would be very helpful?

 

Thanks!

Tim

Community Support Team
Community Support Team

Re: Recurrence - Running a flow during business hours on business days

How to tell if the current time is within business hours

Question

Can you write a condition to check whether current time is within business hours?

Answer

Currently there is no action or feature available to allow you check whether the current time is within business hours.

 

The following steps outline a way to check the hour field against a given time. This makes use of UtcNow() function as the available input value.

 

Steps:

1. Add a condition, click Advanced options

2. Copy and paste the following formula:

   @and

        GreaterOrequals(

                   formatdatetime(utcnow(),'HH:ss'),

                   formatdatetime('8:00','HH:ss')

          ),

         lessOrEquals(

                   formatdatetime(utcnow(),'HH:ss'),

                   formatdatetime('18:00','HH:ss')

           )

      )

In the condition above, we define the working hour as 8:00 to 18:00 in UTC time zone.

 

The condition would check whether the given time is within the hour range. If it is, it triggers the wanted actions.

 

As the date/time format by default contains the year, month, and day, we need to use the formatdatetime function to isolate the time information.

 

You may also use dayofweek with the And function to disregard Saturday and Sunday:

 

@and(

      not(equals(dayofweek(UtcNow()),0)),

      and(

           not(equals(dayofweek(UtcNow()),6)),

           and(

            GreaterOrequals(

                   formatdatetime(utcnow(),'HH:ss'),

                   formatdatetime('8:00','HH:ss')

                                     ),

             lessOrEquals(

                   formatdatetime(utcnow(),'HH:ss'),

                   formatdatetime('18:00','HH:ss')

                                 )

                   )

             )

)

 

 

Please note that the time settings in Microsoft Flow use UTC. You may need to convert the range for your local time zones to work.

 

If you have any further questions, or you need any further assistance to customize this flow, please feel free to post in the Microsoft Flow forum.

 

Regards,

Michael Shao

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Super User
Super User

Re: Recurrence - Running a flow during business hours on business days

Hi, Thanks for sharing.

 

I took a slightly diferent approach so thought i'd link it here to see what others thought.

 


Did I answer your question? Mark my post as a solution!

Proud to be a Flownaut!


timr
Level: Powered On

Re: Recurrence - Running a flow during business hours on business days

Thank you for the assistance. Since I need the flow to run 7 days a week I didn't use the day of week function, but I did make some modifications and ended up with the following:

 

@and(

   GreaterOrequals(

     convertTimeZone(utcnow(), 'UTC', 'Central Standard Time', 'HH:mm'),

     formatdatetime('6:00','HH:mm')

   ),

   lessOrEquals(

     convertTimeZone(utcnow(), 'UTC', 'Central Standard Time', 'HH:mm'),

     formatdatetime('22:00','HH:mm')

   )

)

Super User
Super User

Re: Recurrence - Running a flow during business hours on business days

Nice work timr.

Great to see more tailored usage of date & time to suit.

 

*Thumbs up*


Did I answer your question? Mark my post as a solution!

Proud to be a Flownaut!


Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Users Online
Currently online: 272 members 6,620 guests
Please welcome our newest community members: