SharePoint Integration For Work Order - Part One

This article is about using out of the box SharePoint integration for Work Order entity from Field Service.

Introduction

 
Recently, while working on the Field Service project, we got a requirement to setup SharePoint integration where the customer wanted to use a folder structure based on the account entity. By default, the entity-based folder structure is not supported for work order entity, so we used Flow to implement this requirement. In this article, we are going to discuss the same.
 

Requirement

 
Implement account entity folder structure for work order entity so that all the work order related documents are stored under the parent customer folder hierarchy.
 

Solution


When I got this requirement, I thought it could be achieved using out of the box configuration but when I completed the SharePoint integration setup and tested it, I found Dynamics 365 CE was not creating folders for work order entity under parent service account, instead it was creating a work order folder under a standalone work order document library. When I tried to upload a document in child opportunity, it was creating an opportunity folder correctly under parent account in SharePoint. When I was troubleshooting this issue, I found this KB which explains why work order document is not created under account hierarchy. It's because work order entity has multiple N:1 relationship record with Account entity.
 
With the exception of the opportunity and contract entities, a hierarchical folder structure will not be automatically created in SharePoint for entities that have more than one many-to-one (N:1) relationship with the parent entity.
 
After identifying the issue, the next step is to fix it with minimal effort and Microsoft Flow came into my mind, as I have used it earlier for SharePoint integration. Let’s see how we can create a Work Order structure under Account.
 
The whole flow to create work order folder is divided into two parts, the first part is below where we added three steps,
  1. The first step is to start flow when a new work order record is created so we selected Create step from Dynamics 365 connector.

    SharePoint Integration For Work Order

  2. The second step is the record step to get the service account record because we also need the customer name for SharePoint folder path.

    SharePoint Integration For Work Order

  3. There is no direct option to create a folder in SharePoint but we can use Create File option from SharePoint connector where we can upload dummy file, and it will set up a folder for us :)

    SharePoint Integration For Work Order
We have created a SharePoint folder for a work order under account now, but Dynamics 365 CE SharePoint won’t use this folder unless we set up Document Location record, and that’s the tricky part. To create a document library record, let’s first understand how the document location record is created in Dynamics 365 in the folder structure hierarchy. Here is the screenshot of the document location records, when we have uploaded document under opportunity created HIMBAP customer.
 
SharePoint Integration For Work Order
 
As you can see in the above screenshot,  record 1 is created for the Account folder in the SharePoint site location. After that, we have record 2 created for HIMBAP account under the Account location. Opportunity record is created under the Account folder because we have implemented a folder hierarchy structure. After that, Demo opportunity record is created which refers to the Opportunity document location record, so these records are related using the following sequence.
 
SharePoint Integration For Work Order
 
And we need to implement the same sequence for our work order entity. We will discuss the document location part in the next article, so stay tuned!!