1

我正在尝试通过 SharePoint Web api 过滤标准日历事件,我的查询如下所示:

/_api/web/lists/getbytitle('calendar')/items?$filter=( EventDate  ge  datetime'2013-01-26T22:00:00Z')&$select=Title,EventDate,ID 

查询不起作用,我收到此错误:

'DateTime' 类型的字段 'EventDate' 不能在查询过滤器表达式中使用

错误详情:

{"error":{"code":"-1, Microsoft.SharePoint.SPException","message":{"lang":"en-US","value":"'DateTime' 类型的字段 'EventDate' ' 不能在查询过滤器表达式中使用。"},"innererror":{"message":"类型为 'DateTime' 的字段 'EventDate' 不能在查询过滤器表达式中使用。","type":"Microsoft .SharePoint.SPException","stacktrace":" at Microsoft.SharePoint.SPListItemEntityCollectionCamlQueryBuilder.CheckFieldRefUsage(SPField field, FieldRefUsage fieldRefUsage)\r\n at Microsoft.SharePoint.SPListItemEntityCollectionCamlQueryBuilder.SetFieldRef(XmlWriter writer, String fieldPath, FieldRefUsage fieldRefUsage, Action` 1 attributeAction)\r\n 在 Microsoft。SharePoint.SPListItemEntityCollectionCamlQueryBuilder.SetWhereBinaryOp(XmlWriter writer, EdmParserNode parseNode)\r\n 在 Microsoft.SharePoint.SPListItemEntityCollectionCamlQueryBuilder.SetViewQuery(SPQuery 查询, XmlWriter writer, StringBuilder sb)\r\n 在 Microsoft.SharePoint.SPListItemEntityCollectionCamlQueryBuilder.BuildCamlQuery()\r \n 在 Microsoft.SharePoint.SPListItemEntityCollectionCamlQueryBuilder..ctor(SPList 列表,RESTfulQuery restQuery,Nullable`1 itemId)\r\n 在 Microsoft.SharePoint.SPListItemEntityCollection.TryWriteAsOData(ODataWriter writer,RESTfulQuery 查询,ProxyContext proxyContext)\r\n 在Microsoft.SharePoint.Client.ServerStub.Write(Object value, Uri path, ODataWriter writer, RESTfulQuery query, ProxyContext proxyContext)\r\n 在 Microsoft.SharePoint.Client.Rest.RestRequestProcessor.Process()\r\n 在 Microsoft。SharePoint.Client.Rest.RestRequestProcessor.ProcessRequest()\r\n 在 Microsoft.SharePoint.Client.Rest.RestService.ProcessQuery(Stream inputStream, IList`1 pendingDisposableContainer)","internalexception":{"message":"该字段'DateTime' 类型的 'EventDate' 不能在查询过滤器表达式中使用。","type":"Microsoft.SharePoint.Client.InvalidClientQueryException","stacktrace":""}}}}Microsoft.SharePoint.Client.InvalidClientQueryException","stacktrace":""}}}}Microsoft.SharePoint.Client.InvalidClientQueryException","stacktrace":""}}}}

是否可以在过滤查询表达式中以某种方式使用 DateTime 字段类型?

更新:我发现我可以通过 ListData.svc 做到这一点,例如

/_vti_bin/ListData.svc/Calendar?$filter=StartTime+ge+datetime'2011-11-23'

更多细节在这里 - http://itblog.wolthaus.net/2011/12/rest-filter-datetime/

我试图从 /_api/web/ 查询中删除时间部分,例如

/_api/web/lists/getbytitle('calendar')/items?$filter=( EventDate  ge  '2013-01-26')&$select=Title,EventDate,ID

但它没有帮助,我得到了同样的错误。

4

1 回答 1

0

尝试 Web 服务(旧的、非 REST)端点。这就是我在我的项目中使用的。REST 端点也有许多其他 Odata 构造的问题(例如 $skip)。

https://.../_vti_bin/ListData.svc/Calendar?$select=Title,EventDate,ID&$filter=EventDate ge datetime'2013-01-26'
于 2020-10-12T12:58:48.460 回答