英文:
MS Graph API - Combining And/Or into Filter
问题
我正在尝试在MS Graph的calendarView
端点中使用OData $filter
查询参数。似乎在将AND
与OR
结合使用时出现问题。有人知道正确的语法吗?
Private Sub buildQuery()
m_webQuery = "https://graph.microsoft.com/v1.0/me/calendars/calendar/calendarView"
m_webQuery = m_webQuery & "?$select=subject,organizer,start,end"
m_webQuery = m_webQuery & "&startDateTime=" & Format$(m_projectStart, "yyyy-mm-dd")
m_webQuery = m_webQuery & "&endDateTime=" & Format$(m_projectStart + 365, "yyyy-mm-dd")
m_webQuery = m_webQuery & "&$filter=(contains(subject,'PTO') or contains(subject,'OOO')) and organizer/emailAddress/name eq 'John Doe'"
m_webQuery = m_webQuery & "&$orderby=organizer/emailAddress/name"
m_webQuery = m_webQuery & "&$top=500"
End Sub
**筛选器未能产生正确的结果**
```vb
m_webQuery = m_webQuery & "&$filter=contains(subject,'PTO') or contains(subject,'OOO') and organizer/emailAddress/name eq 'Joe Smith'"
结果应该是包含主题中的PTO或OOO事件,其中组织者是John Doe。我尝试过使用括号组合,但没有成功。
英文:
I'm trying to use the OData $filter
query parameter with the calendarView
endpoint in MS Graph. It seems to work fine until I combine AND
with OR
. Does anyone know the proper syntax?
Private Sub buildQuery()
m_webQuery = "https://graph.microsoft.com/v1.0/me/calendars/calendar/calendarView"
m_webQuery = m_webQuery & "?$select=subject,organizer, start,end"
m_webQuery = m_webQuery & "&startDateTime=" & Format$(m_projectStart, "yyyy-mm-dd")
m_webQuery = m_webQuery & "&endDateTime=" & Format$(m_projectStart + 365, "yyyy-mm-dd")
m_webQuery = m_webQuery & "&$filter= (contains(subject,'PTO') or contains(subject,'OOO')) and organizer/emailAddress/name eq 'John Doe'"
m_webQuery = m_webQuery & "&$orderby=organizer/emailAddress/name"
m_webQuery = m_webQuery & "&$top=500"
End Sub
The filter failing to produce correct results
m_webQuery = m_webQuery & "&$filter= contains(subject,'PTO') or contains(subject,'OOO') and organizer/emailAddress/name eq 'Joe Smith'"
The result should be any event containing PTO or OOO in the subject where the organizer is John Doe
I've tried combining using parans but no avail.
答案1
得分: 1
从测试结果来看,无法将organizer/emailAddress/name
的过滤条件与其他属性的过滤条件结合使用。
因此,要么使用以下方式之一:
m_webQuery = m_webQuery & "&$filter= contains(subject,'PTO') or contains(subject,'OOO')"
或者
m_webQuery = m_webQuery & "&$filter=organizer/emailAddress/name eq 'John Doe'"
任一种方式都可行。
唯一的解决方法是在服务器端使用上述其中一种过滤器进行过滤,然后在客户端应用另一种过滤器。
英文:
From the testing it's not possible to combine filtering by organizer/emailAddress/name
together with filtering by any other property.
So either
m_webQuery = m_webQuery & "&$filter= contains(subject,'PTO') or contains(subject,'OOO')"
or
m_webQuery = m_webQuery & "&$filter=organizer/emailAddress/name eq 'John Doe'"
will work.
Only solution is to use one of the filter above for server side filtering and then apply the other filter on the client.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论