Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Delete Notes and Attachment

Posted on by Microsoft Employee

I want to delete Notes(annotation) and Attachment from account entity using C# web service.

Help me

*This post is locked for comments

  • Priyesh Profile Picture
    Priyesh 7,392 User Group Leader on at
    RE: Delete Notes and Attachment

    Any way to delete only the Attachment and keep the Notes instead?

    Don't want to delete the Note (attachment) itself

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Delete Notes and Attachment
    //Query to get notes with attachment associated with an entity
    
    QueryExpression records = new QueryExpression{EntityName = "annotation",ColumnSet = new ColumnSet("subject","filename","notetext","documentbody"), Criteria = new FilterExpression { Conditions = { new ConditionExpression { AttributeName = "objectid", Operator = ConditionOperator.Equal, Values = {entityId} //Guid Id of account entity record } ,//The below condition is for getting notes with attachments only.Exclude the below condition to retreive all notes. new ConditionExpression { AttributeName = "isdocument", Operator = ConditionOperator.Equal, Values = {true} } } } };
    //Retrieve all notes in entitycollection EntityCollection notes = service.RetrieveMultiple(records);
    //If notes records found if(notes.Entities.Count > 0) {
    //Loop through the entitycollection foreach (Entity note in notes.Entities) {
    // Delete the note record service.Delete("annotation",note.Id); } }
  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Delete Notes and Attachment

    Hi DMat,

    Refer the below MSDN sample to perform CRUD on Annotation-

    msdn.microsoft.com/.../gg328429.aspx

    Hope this helps.

  • Suggested answer
    Arpit Shrivastava Profile Picture
    Arpit Shrivastava 7,518 User Group Leader on at
    RE: Delete Notes and Attachment

    Hello,

    Can take a help from below code:

    private void DeleteNoteAttachments(Guid entityId)
    {

    EntityCollection results = null;

    QueryExpression _noteattachmentQuery = new
    QueryExpression

    {

    EntityName = “annotation”,

    ColumnSet = new ColumnSet("subject","filename","notetext","documentbody"),

    Criteria = new FilterExpression
    {
    Conditions =
    {
    new ConditionExpression
    {

    AttributeName = "objectid",

    Operator = ConditionOperator.Equal,

    Values = {entityId}

    },

    new ConditionExpression

    {

    AttributeName = "isdocument",

    Operator = ConditionOperator.Equal,

    Values = {true}

    }

    }

    }

    };

    using (var service = new OrganizationService("CrmConnection"))

    {

    results = service.RetrieveMultiple(_noteattachmentQuery);

    if(results.Entities.Count > 0)
    {

    foreach (Entity act in ec.Entities){
    service.Delete(act.Id);

    }
    }
    }
    }

     

    Mark this an answer, If it helps.

     

    Cheers
    Arpit
    https://arpitmscrmhunt.blogspot.in

     

  • Suggested answer
    BlackBeard Profile Picture
    BlackBeard 445 on at
    RE: Delete Notes and Attachment
    Hello,

    here you go!
    QueryExpression query = new QueryExpression("account"); EntityCollection retrieveedxpan = service.RetrieveMultiple(query); if (retrieveedxpan.Entities.Count == 0) { tracingService.Trace("nothing found"); } else { foreach (var entity in retrieveedxpan.Entities) { //Here you can remove the attachments

    Kind Regards

    Léon

  • Suggested answer
    Rawish Kumar Profile Picture
    Rawish Kumar 13,756 on at
    RE: Delete Notes and Attachment

    hello,

    Please use querybyexpression to retrieve the attachments from account. Once you have it use foreach loop and do a service.deleted(attachmentid).

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans