我试图过滤我的OData查询结果,以仅检索与当前记录ID相关的活动记录。我使用下面的代码:
var RecordId = parent.Xrm.Page.data.entity.getId();
var options = "$select=Subject&$filter=RegardingObjectId eq guid'" + RecordId + "'";
如何正确过滤guid?
编辑:
这是我的全部功能:
function retrieveActivities() {
///<summary>
/// Retrieves Activities by passing a filter to the SDK.RestEndpointPaging.RetrieveRecords function
///</summary>
clearRelatedGrid();
var number = parseInt(numberOfActivitiesToRetrieve.options[numberOfActivitiesToRetrieve.selectedIndex].value, 10);
var RecordId = parent.Xrm.Page.data.entity.getId();
var options = "$select=Subject&$filter=RegardingObjectId/Id eq (guid'" + RecordId + "');
SDK.REST.retrieveMultipleRecords("ActivityPointer", options, retrieveActivitiesCallBack, function (error) { alert(error.message); }, ActivitiesRetrieveComplete);
}
答案 0 :(得分:4)
按查询过滤fieldname/Id eq (guid'<your guid>')
,所以这应该有效:
var RecordId = parent.Xrm.Page.data.entity.getId();
var options = "$select=Subject&$filter=RegardingObjectId/Id eq (guid'" + RecordId + "')";
答案 1 :(得分:4)
我使用新的Web API v8.2在同样的事情上挣扎。我知道这是在一年前被问到的,但对于今天偶然发现这一点的人来说,这对我来说已经解决了问题:
var options = "$select=Subject&$filter=RegardingObjectID eq " + RecordId;
只需将guid值(作为字符串)直接与对象ID进行比较即可。不要试图告诉API它是一个guid。现在很聪明,知道这一点。我希望这可以帮助其他人使用v8.2。
请参阅此处以获得更深入的解释 https://community.dynamics.com/crm/b/conorssnippetdiary/archive/2015/12/03/web-api-preview-unrecognized-39-edm-string-39-literal
答案 2 :(得分:0)
我在 D365 门户中使用此 OData 查询过滤器。
用于 Guid 过滤
var userId = '{{ user.id }}';
var contactfilteroption = "contactid eq guid'"+userId+"'";
var odataUrI = "https://yourportal.com/_odata/contacts?$filter="+encodeURIComponent(contactfilteroption);
用于字符串过滤
var couponcode = eventdiscountamount.target.value;
var couponcodefilteroption = "stdsscouponcode eq '"+couponcode+"'";
var odataUrI = "https://yourportal.com/_odata/stdssdiscounts?$filter="+encodeURIComponent(couponcodefilteroption);