2017-06-19 69 views
1

我们可以查询网页API端点就像这样:如何从RegardingObjectID查询实体?

GET [Organization URI]/api/data/v8.2/accounts?$select=name&$top=3 HTTP/1.1 
Accept: application/json 
OData-MaxVersion: 4.0 
OData-Version: 4.0 

当响应包含regardingobjectid领域,我们如何发出对那个记录了类似的电话吗?

{ 
"@odata.context": "[Organization URI]/api/data/v8.2/$metadata#accounts(name)", 
"value": [ 
    { 
    "@odata.etag": "W/\"501097\"", 
    "name": "Fourth Coffee (sample)", 
    "accountid": "89390c24-9c72-e511-80d4-00155d2a68d1", 
    "regardingobjectid":"dfdc331f-1cff-4bce-acd7-4815b2e87a30" 
    }, 
] 
} 

是否有查询regardingobjectid的OData的方式,如:

GET [Organization URI]/api/data/v8.2/Entity?regardingobjectid eq 'dfdc331f-1cff-4bce-acd7-4815b2e87a30' 

回答

2

这应该工作,如果我们要与相关记录进行筛选。

GET [Organization URI]/api/data/v8.2/accounts?$select=name&$filter=_regardingobjectid_value eq guid 

注意:无单引号

GUID来查询列的值从相关实体(单个记录),使用expand。例如 - 获得主要联系人细节帐户记录:

?$select=name&$expand=primarycontactid($select=fullname,jobtitle,annualincome) 

我会建议CRM REST Builder建筑的查询。

编号:https://community.dynamics.com/crm/b/mscrmcustomization/archive/2016/10/18/ms-crm-2016-web-api-operations-retrieve-single-or-multiple-records

+0

对不起也许我需要更新我的问题。我想知道是否有可能查询链接的记录?例如,如果相关公司参考机会记录,那么我希望能够查询该机会记录。 –

+1

是的,你可以使用扩展 –

+0

https://community.dynamics.com/crm/b/joegilldynamicscrm/archive/2016/03/23/web-api-querying-with-expand –

1

另一种方法是检索值关于对象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["[email protected]ue"]; 
      var _regardingobjectid_value_lookuplogicalname = result["[email protected]e"]; 
     } 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\"", 
"[email protected]tionproperty": "regardingobjectid_account_email", 
"[email protected]e": "account", 
"[email protected]ue": "Coho Winery (sample)", 
"_regardingobjectid_value": "b3cc84f2-be0d-e711-8104-00155d6fd705", 
"activityid": "b8345099-6074-e711-810f-00155d6fd705" 
} 

[email protected]e给我们的实体名称和 _regardingobjectid_value为我们提供了我们需要查询有关记录ID:

/api/data/v8.1/accounts(b3cc84f2-be0d-e711-8104-00155d6fd705)