Search code examples
dynamics-365dynamics-crm-onlinedynamics-crm-365

Dynamics 365 Plugin - Handling Attachments in Notes (msdyn_richtextfiles)


I am working on a Dynamics 365 plugin to handle file attachments in Notes (annotation entity) and store them in an external system. The process works as expected when users add attachments via the binder in a Note: I can retrieve the file data from the documentbody attribute of the annotation entity using the IOrganizationService.

However, I am encountering an issue when users add attachments by drag-and-drop directly into the Note body.

In this case:

  • The documentbody attribute in the annotation record is empty.
  • Instead, the notetext attribute contains a link to the file, such as: "/api/data/v9.0/msdyn_richtextfiles(22133443-7ab0-ef11-b8e9-000d3ad91f1e)/msdyn_fileblob/$value?size=full"

I do not want to use the API from within the plugin, so I am attempting to retrieve the file directly from the msdyn_richtextfile entity using the parsed GUID from the URL. According to the documentation, the file should be stored as a Base64-encoded value in the msdyn_fileblob attribute of the msdyn_richtextfile entity.

The problem is that when I retrieve the msdyn_richtextfile record using the GUID, the msdyn_fileblob attribute does not contain the file data. Instead, it holds another GUID, and I cannot find documentation or a clear method to resolve this to the actual file content.

I have tried getting both annotation and msdyn_richtextfile with this GUID from msdyn_fileblob but that did not work.

Questions:

  1. Why is the msdyn_fileblob attribute of the msdyn_richtextfile entity not containing the Base64-encoded file as documented?
  2. Is there another entity or attribute that I need to query to retrieve the actual file content in this case?
  3. Has anyone successfully retrieved files added via drag-and-drop in the Note body using the IOrganizationService in a plugin without relying on the API?

Any insights or guidance would be greatly appreciated!

Best regards, Peter


Solution

  • Edited: When you want to download the file using the IOrgService you need to download the file in Chunks using following documentation:

    https://learn.microsoft.com/en-us/power-apps/developer/data-platform/file-column-data?tabs=sdk#use-dataverse-messages-to-download-a-file

    Here you'll also find the code you used to download it using a single API request. So if you want to avoid the WebAPI you need to do the chunk approach.

    Just to mention this here: It works differently for images as there is already the byte64 value in the request.