Sharepoint integration with D365 is a common aspect of any implementation. Often, the out of the box structure is not sufficient to meet the business requirements and there may be a need to create a custom folder structure for each entity record created. This can obviously be done manually, but for most organizations this is simply not an option.

In this example I will show you how to create a Power Automate flow to handle the document location and sharepoint folder structure. There are a couple important points to note before we get started:

  1. You will need to create a template folder with the desired folder structure in sharepoint.
  2. My example uses values relevant to my environment, you will need to plug in your values.
  3. It is best to create a solution for this since you will likely need to test this on a dev/test sharepoint site prior to running in a production environment. Ensure you have proper administrator rights to do so.

 

Create a custom entity to hold the Configuration Settings

First we will need to create two entities that will hold the configuration settings we will use in our flow. For this example we will call them “Configuration” and “Configuration Setting”. There will be a N*1 relationship between them so that you may be able to create many more configuration settings for other scenarios in the future.

In the Configuration Setting entity we will create a record with our JSON parameters which will hold the values for the variables in the Power Automate flow.

 

You will need to provide the following values for the Configuration Setting:

{
“ParentDocumentLocationId”: “00000000-0000-0000-0000-00000000000”,
“SharePointUrl”: “https://yourorganization.sharepoint.com/sites/sitename”,
“LibraryName”: “Name”,
“LibraryPath”: “entityname”,
“FolderToCopy”: “/folder/subfolder”,
}

Create a “template folder” with your folder structure

You will need to define what the folder structure is that we want copy for the target entity. There are a few ways to do this, however, for this example we will just create a folder with the desired folder structure directly in our sharepoint library. It doesn’t really matter where you create it, just put it somewhere it wont be easily deleted.

Create the Power Automate Flow

We will now go through the configuration of the cloud flow. Be sure to make sure you create the flow within a solution so the changes will be tracked properly when you want to export to a production environment.

Trigger

In this example we will set the flow to trigger upon the creation of an entity record. You can do this for contacts, accounts, opportunities, etc.

Initialize variables

Next, we will initialize the variable which will set the name of the Folder. In our example, we are just using the Full Name of the Employee.

Get Configuration Settings

We will now call the values from our configuration settings. In this example we filter the listing action to only include the value field.

Parse Configuration Setting JSON

We will now parse the configuration setting to select our values. I used the following schema but yours may differ depending on the values you use:

{

    “type”: “object”,

    “properties”: {

        “ParentDocumentLocationId”: {

            “type”: “string”

        },

        “SharePointUrl”: {

            “type”: “string”

        },

        “LibraryName”: {

            “type”: “string”

        },

        “LibraryPath”: {

            “type”: “string”

        },

        “FolderToCopy”: {

            “type”: “string”

        },

        “InstanceId”: {

            “type”: “string”

        },

        “DirectoryId”: {

            “type”: “string”

        },

    }

}

 

 

Get Existing Document Locations

In many cases, a sharepoint document location has already been created but if not this step accounts for that scenario. In the next step we are checking if there is already a document location for the record and if not, we will create a folder in sharepoint and the corresponding document location in sharepoint.

In the “Create Sharepoint Folder” action you will notice we have began to use the values parsed from our configuration setting.

In the “Create Document Location” action you will need to define the Parent Site location, the “Regarding” field, and additionally the Relative URL.

Copy Templates Folder to Employee Document Location

In this step we will copy the templates folder structure from that we created in sharepoint to the newly created folder for the entity:

Be sure to set the path using the “Folder Name” variable we initialized in the second step.

I hope you found this useful. Feel free to reach out with any questions!