Resolving Power Automate Outlook Connector’s Create Event Operation Cannot find Calendar Issue


Photo by Jonny Gios on Unsplash

Introduction

One of my iThink 365 team called me up about creating events using the Outlook 365 connector and Create Event activity.

An image showing the Office 365 Outlook connector with the Create Event action.

The Create Event activity would successfully create an event when the Power Automate flow was run by the developer who created the flow. However, when the flow runs as anyone else then it failed with the following error,

“The specified object was not found in the store.”.

When we looked at the configuration of the Create Event operation we could see that the “Calendar”, calendar had been selected. So, if we have selected the right calendar, why is it failing? Why is it that Power Automate cannot find the Outlook calendar?

Well, the point is that the create event operation has a drop-down. This drop-down allows you to choose the name of the calendar to create the event in (as shown below).

However, when the calendar, “Calendar” is chosen it does not use the name of the calendar but rather the id instead. Each calendar has a unique id for each user’s mailbox. When we chose the calendar, rather than using a generic name, the Power Automate editor uses the calendars id. You can see that Id shown in the screenshot below (this was shown by clicking … for the operation and choosing Peek code).

So when Power Automate flow is running, it is running in the context of a user. In our example it is based on the user who started the flow. Now if the user is different to the developer, then they will have calendars with different IDs to the developer. So, in short, the error is right! The flow cannot find the calendar in the store because the calendar with the ID does not exist in the user’s mailbox!

Solution

So how do we resolve this and build something that works?

Well, we need to get the Id for the calendar and use that instead. How do we do that? Fortunately, there is an operation called Get Calendars which allows us to get all the calendars for the current user.

This operation will retrieve all the calendars in the user’s mailbox and using that it is possible to filter the array of calendars and select the id for the default calendar in the user’s mailbox.

This Filter array operation is then configured to take the output of the Get Calendars action and filter using the name “Calendar”.

Now, that we have the array item for the default calendar for the user, we can now use this with Create event by using the following formulae for the Calendar id.

first(body(‘Get_Users_Default_Calendar’))?[‘Id’]

Now that the Create Event action is using this formula to choose the Calendar Id, the operation will be able to find the calendar to successfully create the event in the user’s calendar. Regardless of which user runs the Power Automate flow!

Caveat

There is a caveat for this approach to work, firstly we need to ensure that the flow runs the connection in the context of the user who started the flow.

To do this, browse to the Power Automate Flow details page. Click edit next to the “Run only users” box. Change the drop-down to for the connector to say “Provided by run-only user”, as shown below.

Finally, set the Outlook 365 Connector to use “Provided by run-only user”.

The other point to make is that the flow will need to run in the context of the user that is having the event created in their calendar.

Therefore, there will be some design choices that you will need to make to ensure that the flow is started by the user who is to have the event created in their calendar.

This means that the flow cannot run off a system event or as an application as it will not have permission to write to the user’s calendar. Currently, the actions do not support being run as a service principal. If this were the case, it would be possible to give permission to write in every user’s calendar.

Anyway, hope that helps and please reach out if you have any questions on this.

Issue when changing Power Automate: Dataverse Table Triggers


Introduction

Recently, I experienced an issue where I was making some changes to a Power Automate flow that was using a Microsoft Dataverse trigger. The trigger was being activated when a Dynamics CRM Opportunity was modified.

After a bit of testing, I decided that the approach was flawed, so I deleted the trigger, added another Microsoft Dataverse trigger, and updated the table name from Opportunity to be triggered when the Opportunity Sales Process table entity was modified.

All sounds good but you know what the trigger never fired!

Approach

I tried deleting and adding back the trigger but nothing, the flow did not trigger. How odd?! So, i played around for about 20 minutes but nothing.

The hint

Eventually, I changed the trigger so that it would response to the entity being added and modified. (I was getting a bit desperate) then a funny thing happened.

On saving the flow, an error occurred about not being able to find a registration for a webhook related to a modification event. Sorry, I didn’t make a note of the error message. This got me thinking.

My thought was, I wondered if what was happening was an issue under the hood. I expect that when we are adding these activities and triggers webhook and the like are being created on the fly. So how about if this went wrong and when I deleted the original trigger, it did not get updated and it was still there. So, nothing had been unregistered and registered. Therefore, when the new trigger was added it had not been registered either and so this was why there was no modification webhook for the new entity. Anyway, I continued trying things out and then I had a thought, what might update the webhook?

The fix

The fix turned out to be, for the trigger, click on settings and change the settings to the trigger activity (click … -> settings) and set an option. Now, save the flow.

This fixed the issue with the error when saving. I tested out the Power App and changed the business process flow and low and behold the trigger fired!

Anyway, thought I would blog about this in case someone else has the same issue!