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

I have the same question (0)
  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    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

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 CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans