cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
gosubtle
Frequent Visitor

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.

 

 

 

 

 

7 REPLIES 7
v-micsh-msft
Community Support
Community Support

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.

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

v-micsh-msft
Community Support
Community Support

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.
AlanPs1
Resident Rockstar
Resident Rockstar

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!


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')

   )

)

AlanPs1
Resident Rockstar
Resident Rockstar

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!


Hi @v-micsh-msft!

 

If I need to calculate a 'Due Date' that is 30 BUSINESS DAYS from today, could I utilize any of this logic (I think I could utilize the parts you mentioned about excluding weekend days, but am not sure exactly how 😀)?

 

So far, I know that this formula gives me 30 days from today, but that includes weekends: 

formatDateTime(addDays(utcNow(), 15), 'yyyy-MM-dd')

 

Any ideas on how to calculate 30 business days from today would be greatly appreciated!!!

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,204)