
Hello All
Scenario: We are looking to use the dynamics api on an external application of ours. the requirment is when the user clicks on an account they are tehn taken to a list of all the child accounts.
I've been trying to build this out with the OData web api, though no luck.
What i have achieved is to get the parents acount associated to a child account, but I'm really looking for the reverse here..
Its possible to do for the parent account as we can expand on the parentaccountid lookup, though to do the reverse of this is where I'm stuck..
I envision it would be structured like below,
Account {
ChildAccount {
}
}
Anyway, i hope this makes sense and looking forward to what you have t say about this.
Thanks
Hi,
You can pass Account ID to get all child account using below web api code.
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() "/api/data/v9.1/accounts?$select=accountnumber,name&$filter=_parentaccountid_value eq a16b3f4b-1be7-e611-8101-e0071b6af231", 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.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 accountnumber = results.value[i]["accountnumber"];
var name = results.value[i]["name"];
}
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
Result -