Now Available in Community - MBAS 2019 Presentation Videos
Catch the most popular sessions on demand and learn how Dynamics 365, Power BI, PowerApps, Microsoft Flow, and Excel are powering major transformations around the globe. | View Gallery
2019 release wave 2 Discover the latest updates to Dynamics 365Release overview guides and videos Release Plan | Early Access Availability
Ace your Dynamics 365 deployment with packaged services delivered by expert consultants. | Explore service offerings
Connect with the ISV success team on the latest roadmap, developer tool for AppSource certification, and ISV community engagements | ISV self-service portal
The FastTrack program is designed to help you accelerate your Dynamics 365 deployment with confidence.
FastTrack Program | Finance and Operations TechTalks | Customer Engagement TechTalks | Talent TechTalks
Tested on:Dynamics 365 CE with Field Service version 8.8
I’ve previously written about syncing Dynamics 365 for Project Service Automation’s Resource Assignments to exchange with Flow. For the most part, that Flow can also be used to sync Bookable Resource Bookings to Exchange. The reason we want to do this is because the OOTB feature is deprecated. The Flow covered on this blog post can also delete a Bookable Resource Booking (later BRB) related calendar event from Exchange, if the BRB has a Field Service Status of Canceled.
The objective is to sync Bookable Resource Bookings to a user’s Exchange calendar. When a new BRB is created, a new calendar event is created in Exchange. When a BRB’s Start/End Time, Duration or Booking Status changes, the new values are reflected in the related calendar event in Exchange. If a BRB’s Booking Status equals Canceled, the related calendar event in Exchange is deleted.
This Flow can be downloaded from the TDG Power Platform Bank and the download link can be found at the end of the blog post. Let’s dissect the Flow and see what it contains!
The trigger in the Flow is the new CDS current environment trigger, which has a Create or Update trigger condition. This trigger can be selected when a Flow is built in a solution. The new trigger not only simplifies Flows in general as creating, updating and even deleting is possible by using a single Flow, but it also drives makers to using Flows in solutions. This way customization and ALM best practices can be followed. For this Flow, the trigger either creates a new BRB record or updates an existing one when either Start Time, End Time, Duration or Booking Status fields change.
As the Flow reads, creates and updates calendar events in Exchange, the Microsoft Graph API will be used. This means that an Azure AD Application is needed. My blog post about Creating a Planner plan from a D365 PSA Project with Flow will get you forward with AAD Apps, if you’re not familiar with them.
I have created Compose actions for all different Booking Status values used in Field Service, in case you have a use case where these values are needed. For this example, the Canceled status is the only one that is needed. If you don’t need the other values, you can remove the related Compose actions from the Flow.
The condition in step 2 checks that Work Order on a BRB record contains a value and that Project doesn’t. As PSA also uses Bookable Resource Bookings, we want the Flow to terminate as canceled if it was fired off in PSA’s context. After the condition, Get records actions are used to access the related Work Order, Booking Status and Bookable Resource records. The User record gives us access to a user’s O365 user profile, so that we can get a user’s User Principal Name (UPN).
In step 3, the first action will be to define what the subject of a new event in a calendar will be. For this example, I’ve used dynamic content from Work Order Number. The subject should remain unchanged so that the Flow works as intended so make sure you don’t include an action that changes the subject. Next, we’ll get a user’s calendar with the HTTP – Get Calendars action. We can then parse the JSON and filter the results with a Filter array action. We want to see if Name equals the value set in the Compose – Default Calendar name action. In this example the value is Calendar. The JSON schema is included in the zip file that contains this Flow.
After the Filter array action, we have our hands on the specific calendar we’re interested in. Calendar ID is needed so that we can get, post, patch and delete events so a Compose action is used after the Filter array. This automatically creates an Apply to each loop. Next we’ll use an HTTP action to get all events with a subject that matches what we composed for subject earlier. We should only have a single event in Exchange that matches, however if there are duplicates for some reason, the Flow will still update all events where the subject matches. Next we’ll use parse JSON for the previous HTTP action’s content. The schema is included in the zip file that contains this Flow.
The Compose actions for Start Time and End Time are legacy from the Flow that updates calendar events in Exchange based on PSA’s Resource Assignments. I’ve left them in this Flow as you may have use cases where manipulating Start and End Time is needed. The outputs of the Compose actions are referenced in the Compose – Event body for updated event on true side action. If you remove the Start/End Time Compose actions from the Flow, remember to also edit the Compose action for the event body. The body of the calendar event is a convenient place to indicate the status of the BRB.
In the final 5th step, a calendar event is either created or an existing calendar event is updated or deleted. The first condition checks if Parse JSON – Get events returns a subject that equals the subject we defined in the Compose subject for Exchange calendar event action. If a match is found, an existing calendar event is updated or deleted. Before this is possible, an event ID needs to be composed. We will get our hands on the ID from the previous step’s Parse JSON – Get Events action. The second conditions checks the Field Service Status of the BRB. If the status is Canceled, a calendar event in Exchange is deleted. If the status is anything else, a calendar event is updated.
If a match for the subject is not found, a new event will be created in a user’s calendar. For both the true and false side, the body of the HTTP PATCH/POST is based on the Compose – Event body action.
I hope this blog post helps you in creating calendar events in Exchange based on Bookable Resource Bookings. If you want to try this Flow out, you can download both a managed and an unmanaged solution from the TDG Power Platform Bank here.
Business Applications communities