This example returns data for an account entity with the primary key value equal to 9C33D98E-2FAD-E511-80DE-6C3BE5A8380C. This query also expands data from the related opportunities of Account and related tasks using the respective single-valued and collection-valued navigation properties: opportunity_parent_account and Account_Tasks. To identify the appropriate properties and navigation property names to use for the account entity, see the account EntityType
function RetrieveAccountData()
{
var organizationUrl = Xrm.Page.context.getClientUrl();
var query = "accounts(9C33D98E-2FAD-E511-80DE-6C3BE5A8380C)?$select=accountcategorycode,accountnumber,creditonhold,createdon,numberofemployees,name,revenue&$expand=opportunity_parent_account($select=createdon,name),Account_Tasks($select=subject,scheduledstart)";
var req = new XMLHttpRequest();
req.open("GET",organizationUrl + "/api/data/v8.0/" + query, true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.onreadystatechange = function () {
if (this.readyState == 4) {
req.onreadystatechange = null;
if (this.status == 200) {
var RetrievedAccount = JSON.parse(this.response);
console.log(RetrievedAccount);
alert(RetrievedAccount.name);
} else {
var error = JSON.parse(this.response).error;
alert(error.message);
}
}
};
req.send();
}