Sunday 29 August 2021

Files in Dynamics 365 CRM Part 2

 The last piece I worked on was to create the files in SharePoint and link them to the Document Location.

if you did not read part 1, kindly check it out here.

To create the file on SharePoint, I need two important requirements, the filename, and filecontent.

For Filename: You can access the file attribute from the FileAttachment entity. 

The output used in the filter array is the GUID of the file uploaded.

For FileContent:


SharePoint file creation


Because we have already linked the SharePoint to the right Document Location, the file created in SharePoint is visible in Document Location for that record


Files in Dynamics 365 Part 1

 I recently worked on a project that involved handling files with SharePoint and Dynamics 365 CRM. While all the scenarios are connected, it took me a few days to get the output I desired, so I decided to do a little safe-keeping by blogging it.

The scenarios

  1. Stop default SharePoint Document Location creation in Dynamics 365 CRM and create a custom document location
  2. Upload Files into Dynamics 365 CRM using the File Data Type
  3. File uploaded in No 2. should be created in the SharePoint Folder for the associated record and also linked to the associated Document Location.
Let's dig in

Stop default SharePoint Document Location creation in Dynamics 365 CRM and create a custom document location

This was achieved in two parts (using a Real-time workflow and Power Automate )

First Part


Real-Time workflow was used to disable the default document location that is created when the "File" tab of the associated record is clicked.

The workflow is created on "Document Location" entity. I simply added a condition that states:
and added a step to cancel the creation

Note: The flow cancels default document location creation for the entities in the condition.

Second Part:


I created a 5 step Power Automate and the final output is this:

Let's break it down (The custom document location is created for opportunity)
  • Step 1:  

  • Step 2: I filtered the rows to return using the Odata query. 
    name eq 'Documents on Default Site 1' and _regardingobjectid_value eq null and relativeurl eq 'opportunity'
    Note: The "relativeurl" changes depending on the entity and a "Documents on Default Site 1" has been created for the opportunity as a Document Location in Dynamics CRM


  • Step 3: 

  • Step 4:  I used an "OData.Id" from Step 3. 
    outputs('DocLoc')?['body/value']?[0]?['@odata.id']
  • Step 5: The "ODataId" is from Step 4
  • Final Result:


Upload Files into Dynamics 365 CRM using the File Data Type

This is quite straightforward. A file datatype control was added to the form and I was able to upload files. Questions around where the files are stored may arise which is not clear now, but I am still researching this.