javascriptdynamics-crmdynamics-crm-2011xrmservicetoolkit

CRM 2011 javascript get child entity ID's(1:N relationship)


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?


Solution

  • 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);