
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)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.
Hope this helps.