Power Community

Power Community

Synchronise Microsoft Shifts with Outlook Calendars in Power Automate the 2024 way

I’ve been planning to rewrite my Synchronise Microsoft Shifts with Outlook Calendars in Power Automate post for quite a while. This post will give you the new and more efficient way of implementing a synchronisation process between Shifts and Outlook.

Setup of Microsoft Shifts

In Microsoft Teams I’ve added the Shifts app and I’ve added a number of shifts. But users may not go to shifts as they will not get alerted when a new shift is planned in.

Microsoft Shifts

The need for synchronising shifts with Outlook Calendars has been a common one. In my earlier mentioned post many people for some help implementing the process. In this post the easy steps for you to build this process. If you need any help then feel free to open a chat of course.

In this post I will share the base process. To use this in a production environment you might want to add some error handling and some other small improvements. But as a base process the described flow will work.

Create the flow to synchronise Microsoft Shifts with Outlook Calendars

The process that we are going to create is best run using an account specific for resource scheduling. This account will need to have an Outlook Calendar so that invites can be added to that calendar and any Shift owners can be invited to those events.

I’m going to start with the When a shift is created, updated or deleted trigger. In the past I has to use a scheduled flow. This meant that ever so often calendars would be updated. Now the updates is near instant. This of course is a great improvement.

Synchronise Microsoft Shifts with Outlook Calendar flow

Get the Shift details

The above mentioned trigger will start our flow and give us some basic details about the shift that triggered our flow. however the majority of the details will need to be collected with a different action.

We get get the shift details using the Get a shift action.

Synchronise Microsoft Shifts with Outlook Calendars in Power Automate the 2024 way Microsoft Power Automate image 32

This Shift ID can be selected form the Dynamic content or by using the following expression:

triggerOutputs()?['body/resourceData/id']

Shared shifts

In Microsoft shifts you can create a shift and once you are happy with it you have to share it with the rest of the team. A Get a shift action will supply a different structure of the data depending on if a shift has been shared or not.

In this flow I’m only going to handle Shared Shifts. We could of course also look at synchronising saves shifts and maybe make them appear in a different colour in outlook.

Synchronise Microsoft Shifts with Outlook Calendars in Power Automate the 2024 way Microsoft Power Automate image 33

This condition uses two expressions:

outputs('Get_a_Shift')?['body/sharedShift']

and

null

The True branch of the above condition will remain empty. This is where we could implement the process around saved Shifts.

Get the assignee

In the False Branch we are going to get the user profile of the user who is assigned to the shift. We need this user to send an invite to.

Synchronise Microsoft Shifts with Outlook Calendars in Power Automate the 2024 way Microsoft Power Automate image 34

The Get user profile action will take the assignee from the Get a Shift action that we added earlier.

You can either select this user form the Dynamic content or use the following expression

outputs('Get_a_Shift')?['body/userId']
Synchronise Microsoft Shifts with Outlook Calendars in Power Automate the 2024 way Microsoft Power Automate image 35

Create, Update and Delete events

As Shifts are Created, Updated and Deleted, we will need to flow into a different branch of a switch step.

The Switch Step works on the following expression, but you can also select this form Dynamic content of course.

triggerOutputs()?['body/changeType']
Synchronise Microsoft Shifts with Outlook Calendars in Power Automate the 2024 way Microsoft Power Automate image 36

Create Event

The Create event branch is the easiest of the three branches.

We Add a Create event(V4) action and select a Calendar that we ant to use to maintain all events. You might want to use an environment Variable for this. So that deployment form Dev -> Test -> Production is easier.

Then The Subject is set to the displayName of the Shift.

outputs('Get_a_Shift')?['body/sharedShift/displayName']
Synchronise Microsoft Shifts with Outlook Calendars in Power Automate the 2024 way Microsoft Power Automate image 37

The Start and End Time properties are slightly tougher. Please have a look at my formatDateTime post for more details. The two expressions used are:

formatdatetime(outputs('Get_a_Shift')?['body/sharedShift/startDateTime'], 'yyyy-MM-ddTHH:mm:00')

formatdatetime(outputs('Get_a_Shift')?['body/sharedShift/endDateTime'], 'yyyy-MM-ddTHH:mm:00')

Notice that the Hours in the formatting are HH rather than hh. This is to ensure that we have a 24 hour clock.

Then the only thing left is the Required Attendees. This is where we get the Mail property form the earlier configured Get User Profile action.

That is the creation of the events done.

Update Events

Now the update events is slightly tricky. The filtering in the Get events(V4) action doesn’t work very well. Hence I’m collecting all the events ( by default this gives only events in the future. So that is fine for now.

Synchronise Microsoft Shifts with Outlook Calendars in Power Automate the 2024 way Microsoft Power Automate image 38

Then The Filter Array action takes all the items from the Get Events and uses the following filter expression:

and(equals(item()?['start'], 
formatDateTime(outputs('Get_a_Shift')?['body/sharedShift/startDateTime'],
'yyyy-MM-ddTHH:mm:00.0000000')),
equals(item()?['end'],
formatDateTime(outputs('Get_a_Shift')?['body/sharedShift/endDateTime'],
'yyyy-MM-ddTHH:mm:00.0000000')
))
Synchronise Microsoft Shifts with Outlook Calendars in Power Automate the 2024 way Microsoft Power Automate image 39

And then the Update event is pretty much the same as the create event action that we configured earlier. With the Id set tot he following expression:

first(outputs('Filter_Array_-_Get_Event_Updated')?['body'])?['Id']
Synchronise Microsoft Shifts with Outlook Calendars in Power Automate the 2024 way Microsoft Power Automate image 40

Delete Event

The delete Event branch is similar to the update branch. The only difference is that we replace the Update event with and Delete Event action.

Synchronise Microsoft Shifts with Outlook Calendars in Power Automate the 2024 way Microsoft Power Automate image 41

And that is the whole process. Compared to the old process from a few years ago, this is now a lot simpler. The main reason for this is the addition of the trigger that we used in this flow

This post was originally published on this site

- Advertisement -spot_img

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement - Advertisement

Latest News

Capture and visualize ideas without spatial constraints using Infinite Canvas in Visio for the web

Following our announcement earlier this year about mind maps in Visio for the web, we’re excited to announce a...

More Articles Like This

- Advertisement -spot_img