Creating Document Location Record Using Flow

Introduction


When we create entity record manually and upload documents to that entity under Document grid, Dynamics 365 CE creates a Document Location record and sets up a folder in Share Point for that entity. But if we are creating entity record using another option and want to attach the document to entity, first we need to create a Document Location record and Share Point folder for that entity. In this article we are going to discuss creating a Document Location and Share Point folder using Flow.
 
Details

Let’s first note what are the prerequisites to create document location.

Prerequisite
 
First you need to make sure that Share Point integration is set up in your organization. For our demo we are not using any specific entity folder like below,
 
Creating Document Location Record Using Flow
 
Now let’s first manually create contact record and upload document and note down parent site details, we can follow the below steps,
  1. Create a dummy contact record
  2. Navigate to Related -> Documents and upload a test
  3. Select file and click on Open Location to make sure it’s opening the correct Share Point location

    Creating Document Location Record Using Flow

  4. Navigate to Settings -> Document Management -> Share Point Document Locations and open document location record created for your test contact.
  5. Click on Parent Site or Location lookup to open record and note the GUID of the record from address bar (note: We can also write a step in flow to query this but for the demo purpose swe are using GUID here)
Now we have the details of what we require, so let’s start creating our flow.

> Navigate to Accounts and select Create Flow under flow drop down, as we want to Create contact record from Account
 
Creating Document Location Record Using Flow
 
This will take you to Flow, if you are using flow for the first time it may ask you to setup it first. You will get a screen like the following, click on Continue
 
Creating Document Location Record Using Flow
 
> Click on + sign to add new step

> Search for Common Data Service (current environment) connector and select Create New Record action from it

> Fill in details like the following
 
Creating Document Location Record Using Flow
 
In the above step we are creating contact using account information using dynamics contents.

> Click on + and add a variable to hold Parent Share Point Site location like below and use the GUID we captured in step 5 above.
 
Creating Document Location Record Using Flow
 
> Add another variable to hold contact id and use formula to format and remove “-” from GUID like following.
 
Creating Document Location Record Using Flow
 
> Again click on + sign and look for same common data service connector and select Create New Record action.

> We need to create Document Location Record and need to fill properties using dynamic content like the following:
 
Creating Document Location Record Using Flow
 
The above action will create a document location record in CRM but now we also need to create this folder in Share Point.

> Again Click on + sign and select Create New Folder action under Share Point and fill in the details like below.
 
Creating Document Location Record Using Flow
 
The above step will create a folder under contact library for our new contact record using its GUID.
 
Now save your flow and navigate to CRM under accounts and run flow to test, it should create contact record and should setup document location record for the new contact.
 
Creating Document Location Record Using Flow
 

Summary


Using the above steps we can create a document location record using flow. We need to keep the following things in mind while creating document location record using flow and common data service current connector:
 
> We need to setup lookup using following way

/accounts/@{triggerBody()?[‘entity’]?[‘accountid’]}

> While using GUID for Share Point we need to remove “-” and change it to upper case
 
I hope this will help someone!

Keep learning, Keep sharing !!