Skip to main content

Notifications

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

How to delete records from the Attachment entity via SDK?

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

  • Edwin71 Profile Picture
    Edwin71 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...

  • erhan.keskin Profile Picture
    erhan.keskin 2,247 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

  • David Jennaway Profile Picture
    David Jennaway 14,063 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)

  • Edwin71 Profile Picture
    Edwin71 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,

  • Verified answer
    erhan.keskin Profile Picture
    erhan.keskin 2,247 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
    Edwin71 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.

  • Suggested answer
    Gilmeyer Profile Picture
    Gilmeyer 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

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: How to delete records from the Attachment entity via SDK?

    Hello,

    Try "annotation".

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans