MS Graph API – 将And/Or合并到过滤器中

huangapple go评论73阅读模式
英文:

MS Graph API - Combining And/Or into Filter

问题

我正在尝试在MS Graph的calendarView端点中使用OData $filter查询参数。似乎在将ANDOR结合使用时出现问题。有人知道正确的语法吗?

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.

huangapple
  • 本文由 发表于 2023年2月14日 03:01:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/75440175.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定