Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to get the data in N:N relation ship in dynamics 365 by using XRM javascript?

(0) ShareShare
ReportReport
Posted on by

Hi,

I created two custom entities en1,en2 and I created the N: N relationship between them. in the en1 entity, I created a grid and for every record, I map some records to en1 record from the en2 record. Now I need to get some field value(for ex; Price) from the en2 record which is mapped to en1 record by using XRM Javascript.

can anyone Please suggest How to fix this issue.

Thanks in advance.

*This post is locked for comments

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 Moderator on at
    RE: How to get the data in N:N relation ship in dynamics 365 by using XRM javascript?

    Hi Indrasena,

    When you create N:N entity, CRM internaly creates an intersect entity (which you can see in the relationship). You can query this entity just like any other entity.

    Below is the code to retrieve all the accounts for a specific lead (using the OOB accounleads N:N relationship)

    ============

    var req = new XMLHttpRequest();

    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accountleadscollection?$select=accountid&$filter=leadid eq C3CF3B9D-233E-E811-814A-C4346BDC1F11", true);

    req.setRequestHeader("OData-MaxVersion", "4.0");

    req.setRequestHeader("OData-Version", "4.0");

    req.setRequestHeader("Accept", "application/json");

    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");

    req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");

    req.onreadystatechange = function() {

       if (this.readyState === 4) {

           req.onreadystatechange = null;

           if (this.status === 200) {

               var results = JSON.parse(this.response);

               for (var i = 0; i < results.value.length; i++) {

                   var accountid = results.value[i]["accountid"];

               }

           } else {

               Xrm.Utility.alertDialog(this.statusText);

           }

       }

    };

    req.send();

    ================

    You can use CRM Rest Builder to build query for your custom entities.

    github.com/.../CRMRESTBuilder

    Hope this helps.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,436 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans