Hi,
You can retrieve child records using web api as below.Here all child contacts of parent accounts are retrieved:
function retireveAllChildContacts() {
var parentAccountId = Xrm.Page.getAttribute('parentcustomerid').getValue();
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.0/contacts?$select=accountrolecode,firstname,fullname,gendercode,lastname,middlename,_ownerid_value&$filter=_accountid_value eq " + parentAccountId + "", false);
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=\"OData.Community.Display.V1.FormattedValue\"");
req.setRequestHeader("Prefer", "odata.maxpagesize=10");
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 accountrolecode = results.value[i]["accountrolecode"];
var accountrolecode_formatted = results.value[i]["accountrolecode@OData.Community.Display.V1.FormattedValue"];
var firstname = results.value[i]["firstname"];
var fullname = results.value[i]["fullname"];
var gendercode = results.value[i]["gendercode"];
var gendercode_formatted = results.value[i]["gendercode@OData.Community.Display.V1.FormattedValue"];
var lastname = results.value[i]["lastname"];
var middlename = results.value[i]["middlename"];
var _ownerid_value = results.value[i]["_ownerid_value"];
var _ownerid_value_formatted = results.value[i]["_ownerid_value@OData.Community.Display.V1.FormattedValue"];
}
}
else {
alert(this.statusText);
}
}
};
req.send();
}
Hope this helps:)