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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans