Showing results for 
Search instead for 
Did you mean: 

How-to copy attachments from the CDS to SharePoint Online

The Common Data Service (CDS) has the possibility to add attachments to a record of a entity when using an canvas app. You could have the use case that you want to copy such attachments to SharePoint Online too. This blog post shows you how to do this.

Let me explain the context first. There are 2 custom entities:

  • Case
  • Document

The entity 'Document' contains the attachments. It also has a field 'Case ID' containing the unique number of a case. When the status of a case changes to "Closed", the attachments need to be copied to a certain document library. The entity "Document" contains extra fields for metadata too. SharePoint Online contains similar columns.

Below, the actions used are given and described. At the bottom of this blog post, 4 images are shown to support the text below.

  1. Action "When a record is updated" (Connector "Common Data Service").
    1. Entity "Cases".
    2. I did not yet add any attribute filters for the status change to "Closed".
  2. Action "Condition"
    1. Status is equal to closed
    2. If no > Terminate
  3. Within “yes” branch of action #2 > Action "List records" (Common Data Service).
    1. Entity "Documents".
    2. I use a filter query to filter the documents belonging to that case using the field "Case ID".
    3. Image B.
  4. Within action #2 > Action "Apply to Each" #1
    1. Using the output of action #3.
  5. Within action #4 > Action "List records" (Connector "Common Data Service)".
    1. Entity "Notes". I found out that attachments are placed in the default entity "Notes". The magic happens in the filter query:
      1. _objectid_value eq @{items('Apply_to_each')?['ItemInternalId']}
        1. With "@{items('Apply_to_each')?['ItemInternalId']}" being a dynamic expression.
      2. Image C.
  6. Within Action #4 > Action "Apply to Each" #2
    1. Using the output of action #5.
  7. Within Action #6 > Action "Condition"
    1. @items('Apply_to_each')?['documentbody'] is not equal to null
      1. Both the first path and last (null) are dynamic expressions.
    2. When an attachment is deleted via a canvas app, the field "documentbody" is indeed emptied, but the record will remain. I therefor had to add this condition.
  8. Within "yes" branch of action #7 > Action "Create file" (Connector "SharePoint")
    1. File Name > @{items('Apply_to_each')?['filename']}
      1. Using the "apply to each" of action #6.
    1. File Content > @{items('Apply_to_each')?['documentbody']}
      1. Using the "apply to each" of action #6.
  9. Within "yes" branch of action #7 > Action "Update file properties" (Connector "SharePoint")
    1. Properties of the document (entity "Document") are used.
    2. Image D.

The above mechanism works for Word and PDF documents. It does not work for TXT documents.

For my situation, the attachments in CDS need to be moved instead of copied. At this moment, I am not sure if directly deleting a record in the entity "Documents" is allowed. When I do know, I will add a comment to this blog post.

Copy attachments from CDS to SharePoint_A.pngImage A - The complete FlowCopy attachments from CDS to SharePoint_B.pngImage BCopy attachments from CDS to SharePoint_C.pngImage CCopy attachments from CDS to SharePoint_D.pngImage D

Thanks for reading!

Meet Our Blog Authors
  • Working daily with Microsoft Cloud to deliver the needs of my company, my customers and various Microsoft communities and forums. | Office 365 | Flow | PowerShell | PowerApps | SharePoint |
  • Co-founder of, Office 365 and SharePoint expert. Passionate about design and development of easy to use, convenient and flexible products.
  • Microsoft Business Apps MVP. Owner of ThriveFast, an Office 365 consulting company.
  • 7x Microsoft Business Solutions MVP (CRM)
  • I'm keen in MS technologies, SharePoint, Office 365 and development for them
  • Daniel is a Business Productivity Consultant & Microsoft Business Solutions MVP who is very enthusiastic about all things Office 365, Microsoft Flow, PowerApps, Azure & SharePoint (Online). Since the preview, Daniel has been working with Microsoft Flow and later on with Microsoft PowerApps. That led to him being awarded an MVP Award for Business Solutions. He loves to blog, present and evangelize about improving productivity in the modern workspace with these amazing tools!
  • Michelle is an Office 365 solution architect in Twin Cities, MN. She has been delivering business collaboration solutions for years with her focus on SharePoint and Office 365. Michelle is a recent board member of the Minnesota Office 365 User Group and has been a member of the SharePoint community since 2009. She is a frequent speaker at MNSPUG and SharePoint Saturday and co-chaired the Legal SharePoint User Group for 4 years. Her most frequent projects have involved rolling out a large deployment of Office 365, SharePoint Online intranet, build of a "CHAMPS" Office 365 user adoption program and most recently, SharePoint On-Premise to Online Migration. Michelle is very excited about cloud technology as it is shifting her IT Pro focus to collaboration strategy and technical adoption.
  • I'm a Microsoft Office Servers and Services MVP with a special interest in SharePoint, Office 365, Microsoft Flow, Microsoft Teams and PowerApps. I work at Triad Group Plc (
  • Passionate #Programmer #SharePoint #SPFx #Office365 #MSFlow | C-sharpCorner MVP | SharePoint StackOverflow, Github, PnP contributor