I work four days a week so I have a full day off to spend with my two kids. No phone, no data, no colleagues. Just being there, building towers, reading books, play games. If you have children of your own, you know that you can't really program them like computers or scripts. This means that sometimes I have to change this fixed day off, because my kids are sick or the weekly baby-sitter has to swap a day.
It annoyed me a lot that I had to set my Out-Of-Office-message every week (there's no 'repeat' function in it. Please Microsoft, fix this.) and also change it during the week if something was up at home.
I didn't have a server that could run a script to read my inbox and check my availability, or a laptop that was running the whole day, so I was looking for an alternative. Using MS Flow, I could easily create a flow that's triggered by a new incoming e-mail and checks if my calendar is blocked for the day. Changing my OOO is now history.
I kid you not: my colleagues often thought that I was actually working and messing with them.
If you don't feel like building it yourself, you can get the json file here. Simply import it into your MS Flow. Please read below if you want to build it from scratch.
Basically, the steps that are required for building this Flow are quite simple, please keep these in mind:
Visit flow.microsoft.com
Create a new Flow. You'll be prompted what kind of flow you would like. Choose an automated flow. Name it, and choose the trigger.
In this case, the trigger is a new email arriving in your inbox.
Choose the Folder, in my case Inbox.
Maybe you found out already, but in MS Flow a new action is created by clicking 'Add an action'. When I write about creating an action, I'm referring to this button:
Because I want my OOO-message to be personal and different every time it's sent, I will create some variables.
Add an action and search for 'initialize' to initialize a variable:
Name the variable 'var_salutation' and set the Type to 'String'
Now, create another action called compose a variable. In the popup, click on the tab 'Expression' to enter your formula. Use the formula below:
if(less(int(formatDateTime(utcNow(),'HH')), int(11)),'Good morning ',
if(lessOrEquals(int(formatDateTime(utcNow(),'HH')), int(14)),'Good Day ',
if(lessOrEquals(int(formatDateTime(utcNow(),'ss')), int(30)),'Dear ',
'Hello ')))
This formula returns a string with a salutation, based on the hours of the day. Up untill 12 pm (it says 11 in this formula, something with CET time settings) it says Good morning. Between 12 and 3pm it says Good day. After 3pm it'll look at the seconds: 30 seconds or lower? It says 'dear', otherwise 'Hello'. This is one of many ways to make strings/texts random.
We now have an empty variable, and a calculation which results in a string. We want the created string to be put into the empty variable. Do this by a new action: 'Set variable', as shown below. In the dropdown menu, choose the empty variable that you want to fill (in this case, var_salutation). For Value, choose the Output from the Dynamic content.
Repeat these steps for:
The screenshots of and the formulas for each variable are provided below.
var_received_email
if(equals(int(rand(1,3)), int(1)),'Your message has reached me.',
if(equals(int(rand(1,3)), int(2)),'Thanks for your message.',
'I got your message.'))
This formula uses another way of a random text, just by using the rand() function. It is set to return a random number between 1-3, and returning the string that comes with that number.
var_body
if(equals(int(rand(1,5)), int(1)),'Today no worky worky, ',
if(equals(int(rand(1,5)), int(2)),'At this moment, I’m not working, ',
if(equals(int(rand(1,5)), int(3)),'I’m not here right now, ',
if(equals(int(rand(1,5)), int(4)),'I’m currently away, ',
'Today I’m on a leave, '))))
var_read
if(equals(int(rand(1,4)), int(1)),'I’ll read your e-mail on a later moment.',
if(equals(int(rand(1,4)), int(2)),'when I’m back, I will read your message.',
if(equals(int(rand(1,4)), int(3)),'I’ll read your message later.',
'When I return, your e-mail will be read.')))
var_cheers
if(equals(int(rand(1,4)), int(1)),'Best Regards,',
if(equals(int(rand(1,4)), int(2)),'Cheers,',
if(equals(int(rand(1,4)), int(3)),'Talk soon,',
'Kind Regards,')))
Next, we want to know if there are any events in the calendar that take all day and are shown as 'Away' or 'Out of Office'.
Create an action called 'Get Events'. Choose your calendar from the dropdown-menu at Calendar id. Place the formula below in the Filter Query, Order By start desc, Top Count is set to 1.
Why? We want this action to return just 1 event that meets the given conditions (in case there are more events)
This will return a single value, this single value will be needed later.
start le <PLACE FUNCTION utcNow() HERE> and end ge <PLACE FUNCTION utcNow() HERE> and isAllDay eq true and (showAs eq 'Oof' or showAs eq 'Busy')
Next up, the Condition. The condition splits the workflow in True and False. We need quite a few in this flow.
The first condition is checking if today is a workday. No use of sending an OOO during the weekend if you ask me.
Create a condition and use the following rule:
@and(greaterOrEquals(dayOfWeek(utcNow()), 1), less(dayOfWeek(utcNow()), 6))
If today is not a workday, we terminate the flow. Do this by adding a Terminate action to the If no branch. It must look like below:
Create another Condition, this time we check if the sender is a 'No reply'. We don't want to have a flow that plays Pong with a No reply emailadress. No reply - OOO - No reply - OOO - No reply - OOO ........
If this is the case, terminate the flow. Add the Terminate action to the If no branch.
Use the following formula in the rule:
@and(not(startsWith(triggerBody()?['From'], 'no-reply')), not(startsWith(triggerBody()?['From'], 'noreply')))
Create yet another Condition, to check if the incoming email is NOT an OOO-message. If this is true, continue. If this is false (so it IS an OOO), terminate the flow. Add the Terminate action to the If no branch to prevent another game of Pong.
Use the following formula in the condition:
@and(not(contains(triggerBody()?['Subject'], 'Office')),
not(contains(triggerBody()?['Subject'], 'office')),
not(contains(triggerBody()?['Subject'], 'Automatic reply')),
not(contains(triggerBody()?['Subject'], 'Automatic Reply')),
not(contains(triggerBody()?['Subject'], 'automatic reply')),
not(contains(triggerBody()?['Subject'], 'autoreply')),
not(contains(triggerBody()?['Subject'], 'Autoreply’')),
not(contains(triggerBody()?['Subject'], 'AutoReply')))
Create the final condition. We need this condition to check if the email comes from someone within the company you work for. If this is the case, Flow can fetch the name of the sender to personalize your message. If not, send a regular email.
Use the following formula (and don't forget to change the domain from 'mycompany' to the company you work for):
@or(endswith(triggerBody()?['From'], 'mycompany.nl'),endswith(triggerBody()?['From'], 'mycompany.com'))
After you've set the formula as the condition, under the yes branche, add the action Get user Profile.
As you see in the image above, for both branches I created the action Apply to each. This is where the value comes in, that you created using the get events action. Basically, this means that if there is an event that meets the given conditions, we will apply the step of sending an email.
Create the Apply to each action by adding an action and choose the value from Get events.
Almost there! We have all the variables in place, and we know if there's an event in the calendar. Time to create the final actions: Send e-mail. Make sure the action falls within the Apply to each.
Set up the action as shown in the image below.
Your Flow now looks like this:
That's it! Just create an event in your calendar and make sure you set the:
Your workflow should now recognize the created event and send an email on your behalf.
Thanks for reading, I hope you enjoy your personalized OOO!