另一种方法是检索相关的对象 id 值
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.1/emails(B8345099-6074-E711-810F-00155D6FD705)?$select=_regardingobjectid_value", 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.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
var _regardingobjectid_value = result["_regardingobjectid_value"];
var _regardingobjectid_value_formatted = result["_regardingobjectid_value@OData.Community.Display.V1.FormattedValue"];
var _regardingobjectid_value_lookuplogicalname = result["_regardingobjectid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
*请注意标题以包含 odata 注释。
哪个应该返回:
{
"@odata.context": "http://xxxx/api/data/v8.1/$metadata#emails(_regardingobjectid_value)/$entity",
"@odata.etag": "W/\"633069\"",
"_regardingobjectid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "regardingobjectid_account_email",
"_regardingobjectid_value@Microsoft.Dynamics.CRM.lookuplogicalname": "account",
"_regardingobjectid_value@OData.Community.Display.V1.FormattedValue": "Coho Winery (sample)",
"_regardingobjectid_value": "b3cc84f2-be0d-e711-8104-00155d6fd705",
"activityid": "b8345099-6074-e711-810f-00155d6fd705"
}
_regardingobjectid_value@Microsoft.Dynamics.CRM.lookuplogicalname
给我们实体名称并
_regardingobjectid_value
给我们查询相关记录所需的 id:
/api/data/v8.1/accounts(b3cc84f2-be0d-e711-8104-00155d6fd705)