1

I need to get child entity(B) ID's from parent entity(A) and use these ID's to get child field values using javascript.

check image

I know, how to retrieve field value, when i have lookup field(N:1) on the entity using xrmservicetoolkit, but not for 1:N relationship.

Can someone help me?

Juraj
  • 43
  • 5

1 Answers1

1

I have used CRM REST builder to generate this code snippet. Basically I am retrieving Fax & FirstName of all the Contacts filtered by AccountId, as Account has 1:N relation with Contact

v1.5.0.0 support crm 2011.

XrmServiceToolkit.Rest.RetrieveMultiple("ContactSet", "?$select=Fax,FirstName&$expand=contact_customer_accounts&$filter=contact_customer_accounts/AccountId eq (guid'7DD7EE05-FC52-E811-A960-000D3A1A941E')", function(results) {
    for (var i = 0; i < results.length; i++) {
        var fax = results[i].Fax;
        var firstName = results[i].FirstName;
    }
}, function(error) {
    Xrm.Utility.alertDialog(error.message);
}, function() {
    //On Complete - Do Something
}, true);
  • 1
    Thanks! When i know function name i could find it on the web. For others: Here is nice eplanation of this function: https://alisharifiblog.wordpress.com/tag/xrmservicetoolkit-rest-retrievemultiple/ – Juraj Dec 19 '18 at 07:28
  • How can i access values returned by this function? I mean i want get values outside the function to use it later, but looks like not possible. I defined array outside the function but always getting undefined. What i am doing wrong? – Juraj Dec 19 '18 at 13:01
  • var pGRLF_AuditJudgement = new Array(); XrmServiceToolkit.Rest.RetrieveMultiple("PGRLF_AuditSubjectJudgementSet", "?$select=PGRLF_AuditJudgement&$expand=pgrlf_pgrlf_pedmtkontroly_pgrlf_auditsubjectjud&$filter=pgrlf_pgrlf_pedmtkontroly_pgrlf_auditsubjectjud/PGRLF_pedmtkontrolyId eq (guid'5D9BE418-7026-E711-BF9B-00155D016403')" , function(results) { for (var i = 0; i < results.length; i++) { pGRLF_AuditJudgement.push(results[i].PGRLF_AuditJudgement.Value); } }, function(error) { alert(error.message); }, function() { }, true); alert(pGRLF_AuditJudgement[0]); – Juraj Dec 19 '18 at 13:04
  • @Juraj add the breakpoint or move the alert inside for loop. This is an Async call so you have to wait for success callback to execute ie function(results) – Arun Vinoth-Precog Tech - MVP Dec 19 '18 at 13:33
  • Moving inside for loop is not want. I'm using alert only for testing. What i need is get array filled with RetrieveMultiple function and compare it with another array filled by another RetrieveMultiple function. So i need to get data out of the function for later use... Is it possible, or i can manipulate with data only inside RetrieveMultiple func? – Juraj Dec 19 '18 at 13:47