我只能根据我检索到的实体记录中的数据来区分父引用。问题是 如何列出特定实体记录的所有子引用?
我有一个帐户实体,我想使用REST API查找所有相关的子实体(联系人等)。
答案 0 :(得分:0)
尝试使用以下代码为父级检索相关的子实体:
function RetrieveRelatedChildEntities() {
var url = Xrm.Utility.getGlobalContext().getClientUrl() + "/api/data/v9.0/EntityDefinitions(LogicalName='account')?$select=LogicalName,DisplayCollectionName&$expand=ManyToManyRelationships,ManyToOneRelationships,OneToManyRelationships";
req.open("GET", url, 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=\"*\"");
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.OneToManyRelationships.length; i++) {
}
}
}
}
}