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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

How to delete data from entity relationship many-to-many in CRM 365?

(0) ShareShare
ReportReport
Posted on by 5

Hi there,

I have two entities one is <A> another is <B>. the data hierachy will be 

<A> serial number (eg. 6685834) <N:N releationship> mapping to multiple records in <B>. for instance:

6685834

AC-1F

AC-2F

AC-3F

currently, I would like to delete AC-1F, AC-2F, and AC-3F. does anyone have ideas on it or sample code.

thanks

WILL

I have the same question (0)
  • cloflyMao Profile Picture
    25,210 on at

    Hi Will,

    We couldn't delete intersect entity records directly.

    You should use DisassociateRequest to disassociate many to many relationship.

    https://stackoverflow.com/questions/8802802/how-to-create-and-delete-data-from-entity-relationship-many-to-many-in-crm-2011

    Regards,

    Clofly

  • erhan.keskin Profile Picture
    2,253 on at

    I assume you are asking it because you faced in Unified Interface?

    If so, check this out

    crmtipoftheday.com/.../

  • Suggested answer
    cloflyMao Profile Picture
    25,210 on at

    Hi Will,

    I would like to correct my answer:

    You can use disassociate action in CRM Rest Builder to delete intersect record easily. 

    pastedimage1576158950175v1.png

    The format for delete operation:

    parent_entity(parent_entity_id)/relationshipname(child_entity_id)/$ref

    Below is my test, a book could be sold in many book stores, a bookstore sells many books.

    I remove a book from a book store.

    var req = new XMLHttpRequest();
    req.open("DELETE", Xrm.Page.context.getClientUrl()   "/api/data/v9.1/new_books(41a5cb80-8c07-ea11-a811-000d3a59f6ff)/new_new_bookstore_new_book(c3aaaf8a-e41c-ea11-a811-000d3a59f6ff)/$ref", true);
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.onreadystatechange = function() {
        if (this.readyState === 4) {
            req.onreadystatechange = null;
            if (this.status === 204 || this.status === 1223) {
                alert("OK!");
            } else {
                Xrm.Utility.alertDialog(this.statusText);
            }
        }
    };
    req.send();

    Thus you can execute the action 3 times for AC-1F, AC-2F and AC-3F.

    Regards,

    Clofly

  • WILL -H Profile Picture
    5 on at

    Hi Clofly,

    thanks for your elaboration on this. I will have it a try. thanks a lot

  • cloflyMao Profile Picture
    25,210 on at

    Hi Will,

    Please let me know whether your problem could be solved with the method. :)

    If you had found my answer helped, please kindly mark as verified, it would be really appreciated.

    Regards,

    Clofly

  • Suggested answer
    WILL -H Profile Picture
    5 on at

    Hi Clofly,

    My colleague had changed another solution to solve it out. and I reckon your solution should be workable.

    Thanks Clofly

  • Community Member Profile Picture
    on at

    I get service.Disassociate("productsubstitute", pr.Id, new Relationship("new_account_productalias"), accts);

    But getting the collection, accts, takes effort.  I want

     service.Disassociate("productsubstitute", pr.Id, new Relationship("new_account_productalias"), true); that just gets them all.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 74

#3
Martin Dráb Profile Picture

Martin Dráb 64 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans