web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

How to delete records from the Attachment entity via SDK?

(0) ShareShare
ReportReport
Posted on by 5

I'm a C# developer and have been tasked with purging records from the Attachment entity for a GDPR requirement.

However when I invoke the 'Delete' method on the Xrm Sdk toolkit (Microsoft.Xrm.Sdk.IOrganizationService.Delete) the following exception is raised - "The 'Delete' method does not support entities of type 'attachment'." - ErrorCode: 0x80040800.

The Delete method works fine against the ActivityMimeAttachment entity and a number of other entities so question is how are you meant to delete Attachment entity records?

Apologies if I'm posting in the wrong place but I couldn't see a developer forum on the list...

I have the same question (0)
  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: How to delete records from the Attachment entity via SDK?

    Hello,

    Try "annotation".

  • Suggested answer
    Gilmeyer Profile Picture
    on at
    RE: How to delete records from the Attachment entity via SDK?

    Hi ,

    Im afraid Attachment entity does not support Delete request as it is not listed in the supported entities docs.microsoft.com/.../microsoft.xrm.sdk.messages.deleterequest.

    As an alternative you have the options listed in here docs.microsoft.com/.../microsoft.xrm.sdk.messages.deleterequest

    Thanks

  • Edwin71 Profile Picture
    5 on at
    RE: How to delete records from the Attachment entity via SDK?

    Hi Rita,

    Thanks for the reply. So I guess my next question is how are we meant to conform to GDPR legislation if we can't delete from the Attachment entity? We have a legal requirement to delete customer data after a certain period of time.

    Is it possible that data in this entity is deleted as part of a cascading delete? I notice there is a relationship between Attachment and ActivityMimeAttachment ie:

    docs.microsoft.com/.../attachment

    Does deleting from ActivityMimeAttachment cause a delete to Attachment?

    Thanks.

  • Verified answer
    erhan.keskin Profile Picture
    2,253 on at
    RE: How to delete records from the Attachment entity via SDK?

    Hi,

    I assume you are either/both talking about purging annotation (Notes) and activitymimeattachment (Attachments) entities. Attachment is not an entity, it is a table in the database. So, activitymimeattachment and attachment tables work together to store the Attachments.

    If you need to delete Attachments, then pass the activitymimeattachment entity to the Delete method.

    If you need to delete Notes, then pass the annotation entity to the Delete method.

    Regards,

  • Edwin71 Profile Picture
    5 on at
    RE: How to delete records from the Attachment entity via SDK?

    Thanks Erhan,

    Figured that was probably the case.

    Any thoughts on removing attachments from Notes whilst retaining the Notes record?

    We were thinking of blanking the 'Filename' and 'MimeType' fields, setting 'FileSize' to zero and 'IsDocument' to No.

    Regards,

  • David Jennaway Profile Picture
    14,065 on at
    RE: How to delete records from the Attachment entity via SDK?

    In addition to 'Filename' and 'MimeType' fields, setting 'FileSize' to zero and 'IsDocument' to No, you should also set the documentbody to null (this field stores the file contents)

  • erhan.keskin Profile Picture
    2,253 on at
    RE: How to delete records from the Attachment entity via SDK?

    Yes, do it. Just make document related fields Null, "IsDocument" field included.

    However, after doing it check in the "Attachment" table if the attachment is deleted from the table.

    docs.microsoft.com/.../annotation

  • Edwin71 Profile Picture
    5 on at
    RE: How to delete records from the Attachment entity via SDK?

    Thanks Erhan and David,

    I've tested this and deleting from the ActivityMimeAttachment entity does indeed delete from the Attachment entity.

    Worth noting that ActivityMimeAttachmentId and AttachmentId are two different Guids! So you need to make a note of the AttachmentId before deleting the ActivityMimeAttachment record or you won't be able to do a check...

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Sahan Hasitha Profile Picture

Sahan Hasitha 271

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 91 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 76 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans