Dynamics gives the ability to save files within a record. These files are stored in SharePoint. Let’s see how we can create a flow to access a document just by using the dynamics record ID.
Prerequisites
- SharePoint Integration should be enabled for the dynamics environment
- SharePoint document management should be enabled for the specific entity
Ok, let’s begin..
Identify SharePoint folder structure
We need to first understand the document structure. In this scenario, I am taking “Opportunity” as my entity.
Go to any Opportunity record and open “Files” tab.

Click “Open Location” and select the location. This should open the SharePoint folder


You would have noticed that for each Opportunity record in dynamics, SharePoint will be creating a corresponding folder per below format.
Opportunity/ <Opportunity Name>_<Opportunity GUID>
Note – folder location could be different depending on the scenario. If your folder structure uses account as the main folder, then your folder location could be something like this :

See how Opportunity subfolder is created inside the specific Account folder? This is a complex scenario and we will discuss this in a future post.
For now, let’s focus on scenario 1 where subfolder is created within the Opportunities folder in SharePoint.
Opportunity(Folder) / <Opportunity Name>_<Opportunity GUID>
Whenever we create an opportunity, a folder will be created with the name “<OpportunityName>_<GUID>” inside the Opportunity folder. Inside that folder, specific record related documents will be saved.
Now with this knowledge, let’s create a sample flow.
Flow Steps:
- Get folder name for the specific record
- Access folder and get the file
- Copy/ Email file
Let’s begin..
- Create a new flow and select type as “Instant Flow”

2. As the first step, we need to provide the CRM record ID and the file name.

3. Now let’s identify the specific folder. We already have record GUID as input.
We can get the Opportunity name using CDS get record action. Select record ID input as item identifier.

4. Now let’s look at the GUID format and SharePoint folder name
- GUID in the system : dbf8d946-8cf6-4390-9e74-65fcfbbb9b92
- SharePoint folder : DBF8D9468CF643909E7465FCFBBB9B92
We need to remove the dashes in guid and transform all letters to upper case.
5. Simply create a string variable for this conversion. For the value, we can use below expression to remove dashes and make it all upper case.
toUpper(replace(triggerBody()[‘text’],’-‘,”))
Here, triggerBody()[‘text’] refers to the “Record ID” input field.

6. Add” Get file metadata using path” action to specify the complete folder path and get the file.

7. Then we can get document content using “Get file content” with the Id from previous step.
8. Finally, let’s add an email action to send the file as an attachment. We can use the file name as the attachment name. Attachment content should be the output of “Get content” action.

All set! Now let’s test this flow.
Upload a sample document to a CRM record.

We need the record ID. This can be taken from the URL. At the end of URL, there is a GUID.
pagetype=entityrecord&etn=opportunity&id=dbf8d946-8cf6-4390-9e74-65fcfbbb9b92
Now we can run the flow. You should get an email with the attachment.


You can extend this flow depending on the scenario. Here are some examples.
- Instead of instant flow, you can use automated flows and triggers
- Instead of email, you can post to MS Teams.
- Instead of email, create a shareable link to the SharePoint file.
The key is to understand folder structure and how folders are created dynamically within SharePoint. Then you can design complex scenarios by adding other actions.
Happy Learning!
Categories: Dynamics 365, Power Automate, SharePoint
Hello,
I have used the same steps to retrieve a file from sharepoint folder and send it via email.
But I’m getting a corrupt file in the email.
Could you kindly help?
LikeLike
Sure, can you verify that you enter the file name with proper extension? Additionally, you can run a test by adding a “Create file” action and creating the attachment somewhere in SharePoint. This would confirm that the file content is valid.
LikeLike
Thank you for your response.
The extension is correct for the document.
I have tested using create file connector and it works, the file is created.
I have tested with different documents it is still the same.
LikeLike
The issue is solved.
The problem was with the extension, in Attachment Name I was not passing the parameter.
Thank you for your help and your post.
Appreciate it.
LikeLike