I’ve worked part-time for some time now. Helps tremendously when you want to spend some time with your children so they can start easy with daycare. It is easy to mark the days you are out of office to your MS Office calendar. However, using the calendar “out of office” events does not activate the autoreply feature.

I remember some things and some things I do not. 90% of the time I forget to activate the autoreply for these individual days (1-2 times a week).

Then I realized this is a task easily automated. Microsoft Flow licences usually come with the Office package and this is the tool to automate your tasks. So let’s get to business and login to flow.microsoft.com, and create our new flow. There are a lot of templates available, but no matches for what I want to do so let’s start from scratch.

Step 1: Start the flow

First I need to select the trigger; how the flow gets started. Let’s use “Schedule –recurrence” type of trigger and configure that to be started once a day, sometime early to be activated early enough. On contrast to logic apps, runs cost nothing, so run as often as you like, but I am fine with once a day.

microsoft flow start the flow

Step 2: Check your existing out-of-office [added 2019-04-05]

If I am away for a longer period (such as summer vacation) I usually do remember to add a well formatted message for everyone as my out-of-office message. And with this flow, we do not wish to overwrite that. This can be easily achieved with two actions:

i) Adding “Get mail tips for a mailbox” action for my own mailbox

ii) use simple condition “@empty(body(‘Get_mail_tips_for_a_mailbox’)?[‘AutomaticReplies’]?[‘Message’])” to branch the processing into going forward (“yes”) and do nothing (“no”)

Thank you Ivan Dretvic (Australia) for showing me the light on this. Missing this step used to be a known issue with my flow but now it is perfect 🙂

 

Step 3: Check your calendar events

Then I need to check my calendar events. So I add action “Office 365 Outlook – Get Events (V2)”. Note the “events” there is also one for “event” for getting a single action, but I am not interested in the details.

microsoft flow check calendar events

Ok, a lot of options here.

Calendar id:

I’ll just use my default calendar (which shows automatically on the list as I logged in to flow.microsoft.com using my company AD login).

Filter Query:

So I want to have all the all-day events for today. But I need also to consider the type of the event; I want only the ones marked as “Busy” or “Out of office” on my calendar. As I am interested only on events for today I’ll search for ones already started and not yet finished (works fine for all-day events).

It takes a bit of googling to find out the correct variables and values but it only took me 10 minutes to get to this:

(start le @{utcNow()} and end ge  @{utcNow()} and isAllDay eq true and (showAs eq ‘Oof’ or showAs eq ‘Busy’))

We do not need to order the results, we are satisfied to find a single result, so let’s use 1 as top count.

Step 4: Update your out-of office

Then the final step.

Naturally I only want to activate the replies if there there was an event returned from the previous step. I could use a condition here, but I do not actually need the “no” branch at all so, I’ll use “apply to each”. There is also less clicking to do J.

I’ll use the values from previous step as the input for the loop and add action “Office 365 Outlook – Set up automatic replies” within the loop:

microsoft flow update your out-of-office

Again, some things to configure. I’ll use the scheduled option as I want only to use the automatic replies for the current day (the next run tomorrow will take care of that day).

I want to start the out of office immediately so I’ll add expression utcNow().

I’ll just keep this on for the end of day. There are probably many ways to get this but I’m using expression:

formatDateTime(addDays(utcNow(),1),’yyyy-MM-dd’)

After setting up the reply messages (I could create a stylish message using html, but I’m not going there), I can test this with the “Test” button on top right corner. When testing I encourage to keep in mind that this actually does update the behaviour of out-of-office. Do not start testing with external audience before you know it works.

However; with the above I can only send a message that I am unavailable. I cannot tell people when I will be available. I could make a guess based on the event properties, but that would only be a guess.

Improvement: Dynamic reply with the date you will be available

As there is no ready action for getting the next available time we need to be a bit more creative. First, let’s create some variables, I need to use the “Initialize variable” action on the bottom level, so I’ll just initialize these after the trigger.

ReservedDays, integer, set as 1

SlotFound, Boolean, set as false

searchDate, string

Then what I need is a “Do until” loop just before the setting of automatic replies, still within the apply to each.

Basically I need to check the events again, this time for the coming days. But, I need to consider also the weekends, I will not be available then for business.

Without going into every detail, here is the new content for the original “apply to each” loop:

microsoft flow dynamic reply with date you will be available

 

A few tips however

This time I am interested in days where there are no events, so we can use the length of the value list as condition.

length(body('FutureAvailabilitySearch')?['value'])

 

The condition to check if the currently processed date is part of the weekend is

or(equals(dayOfWeek(variables('searchDate')), 6), equals(dayOfWeek(variables('searchDate')), 0))

 

(6=Saturday, 0=Sunday)

Thirdly, the first available date can be set on the final step using (note Finnish date format)

formatDateTime(addDays(utcNow(),variables('ReservedDays')),'dd-MM-yyyy')

 

Note that the “increment variable” action for adding day to search date must be on both “If no” branches (other one not visible on diagram).