DEV Community

Barret Blake
Barret Blake

Posted on • Originally published at barretblake.dev on

Copy Events From One Calendar To Another

I recently began offering mentoring sessions for developers who were just getting started in their careers. Calendly offers a great way to allow people to sign up for sessions that fit into my calendar. And while it’s great that it will check two calendars for my availability, it won’t add the event to multiple calendars.

But that doesn’t fit into my needs. I wanted the events to be created on my personal Outlook calendar for various reasons, but I also wanted the events added to my work Outlook calendar so I don’t get double-booked with both work and personal events. Power Automate to the rescue once more!

Creating Our Flow

The exact flow trigger will depend on the calendar where Calendly will add your registered events. In my case, it will be on my Outlook.com account. So I will be starting with the Outlook.com trigger “When a new event is created (V2)”. The only required parameter is the ID of the calendar you want to watch for new events.

03-CalendarCopy-CreatingFlow
03-CalendarCopy-CreatingFlow

Time Variables

In order to create a copy of our event on a different calendar, we will need to create a couple of variables to handle the event’s start and end times. You can’t directly reference the start and end times from the trigger. When they come out of the trigger, they’re treated as strings. When we add them to the copy of the event, we’ll need to parse them into datetime values. Using variables to hold them temporarily makes that a little easier to manage.

03-CalendarCopy-TimeVariables
03-CalendarCopy-TimeVariables

Do We Copy?

The next thing we’ll need to do is to check if this is an event we want to copy. We don’t want to copy every event to the other calendar, just our Calendly invites. There are a number of ways to do this check. In my particular case, the subject line for all my Calendly session events have a subject line of “<> and Barret Blake”.

So, for me, to keep it simple, I just check if the subject line of the event contains the phrase “and Barret Blake”. If it doesn’t, I do nothing. If it does, we’ll copy the event.

03-CalendarCopy-SubjectLine
03-CalendarCopy-SubjectLine

Copy the Event

In my case, I’m adding the event copy to my Office 365 work calendar. So the action we’ll need is the Office 365 Outlook “Create event (V4)”. We’ll need a few values to pass in. First, as before, we’ll need to select the ID of the calendar to add the event to. If you haven’t customized it, generally the default calendar ID in both Office Outlook and Outlook.com is “Calendar”. Crazy, right?

At the minimum, we also need to add a subject, start time, end time, and time zone. Subject can be whatever you want. For me, I copied the subject created by Calendly and then added a note on the front to emphasize this is a mentoring session.

For the start and end time, we’ll need to make use of the parseDateTime function, like so:

parseDateTime(variables('StartTime'))
parseDateTime(variables('EndTime'))
Enter fullscreen mode Exit fullscreen mode

The parseDateTime function has optional second and third arguments for locale and format. However, the default output from Outlook.com event trigger passes the time in the UTC locale and default format, so as long as your “Time zone” parameter is set correctly, you shouldn’t need to mess with that.

The “Time zone” is the last required parameter and should be set to your personal time zone. In my case, that’s Eastern time. If that’s set correctly, you should see new events set correctly on the destination calendar. However, you may need to do some experimenting to find the right settings for the parseDateTime and Time zone.

If you click on the advanced options button, you can see a number of things that you can set on the event. In my case, I wanted to also include the body and location values of the event so that I would have the Zoom meeting information in both copies of the event. So in both cases, I just copied the same fields from the trigger.

I also changed a couple of other settings. I added a 15-minute Reminder, set “Is reminder on” to Yes, set my event as “busy” and Sensitivity as “private”. This way I’m not unnecessarily sharing private information about the person I’m speaking with.

03-CalendarCopy-CreateCopy
03-CalendarCopy-CreateCopy

Conclusion

That’s it. I’ve got a simple copy event flow that will make sure if I’m scheduled to speak with someone, it also shows me as busy on my work calendar. It’s not a perfect solution. For instance, if the event changes or gets canceled, it doesn’t sync correctly. These would require a couple of other flows to watch for and process changes or cancellations. But it’s a pretty good start.

The post Copy Events From One Calendar To Another first appeared on Barret Codes.

Top comments (0)