Access files stored in Dynamics 365 records via PowerAutomate

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.


  1. SharePoint Integration should be enabled for the dynamics environment
  2. 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:

  1. Get folder name for the specific record
  2. Access folder and get the file
  3. Copy/ Email file

Let’s begin..

  1. 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.


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.


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.

  1. Instead of instant flow, you can use automated flows and triggers
  2. Instead of email, you can post to MS Teams.
  3. 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

Tags: ,

4 replies

  1. 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?


    • 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.


      • 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.


  2. 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.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: