从图形 API 查询中过滤的字段中去除空白字符的方法

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

How to strip whitespace from fields filtered in graph API queries

问题

我正在使用Microsoft Graph在Active Directory的mobilePhone字段上进行搜索,使用startsWith关键字。

$filter=startsWith(mobilePhone,'+44765')

请参阅https://learn.microsoft.com/en-us/graph/query-parameters?tabs=http#odata-system-query-options

然而,数据存在着没有标准化的格式

例如
+44 765 432 109
或者
+44 765 432109
+44 765432 109

因此,除非在相关点包括空格,否则应用的过滤器将无法跨所有数据起作用。
因此,不可能同时查询所有数据。

如果这是SQL,人们可以使用类似以下的内容

WHERE TRIM(mobilePhone) LIKE '%'

这将允许应用过滤器而无需空格,跨所有记录。

使用Graph API是否有一种方法可以剥离查询过滤器中字段的空格,以使过滤器数据不需要担心空格格式,就像SQL中可能的那样?

英文:

I am using Microsoft graph to do search on the mobilePhone field in active directory, using the startsWith keyword.

$filter=startsWith(mobilePhone,'+44765')

see https://learn.microsoft.com/en-us/graph/query-parameters?tabs=http#odata-system-query-options

However, the data exists with no standardised formatting

For example
+44 765 432 109
or
+44 765 432109
+44 765432 109

So the filter applied will not work across all the data unless spaces are included at the relevant points.
Therefore it is impossible to query all the data at the same time.

If this were SQL one would use something like

WHERE TRIM(mobilePhone) LIKE '<filter>%'

which would allow the filter to be applied without spaces, across all records.

With the graph API is there a way of stripping whitespace out for fields in the query filter, so that the filter data does not need to worry about space formatting, in the same way that is possible with SQL?

答案1

得分: 1

OData协议支持trim函数,但不支持Graph API。

使用trim的请求

https://graph.microsoft.com/v1.0/users?$filter=startsWith(trim(mobilePhone),'%2B420')&$count=true
Header: ConsistencyLevel:eventual

将返回Request_UnsupportedQuery错误代码。

唯一的方法是组合所有形式

https://graph.microsoft.com/v1.0/users?$filter=startsWith(mobilePhone,'%2B44765') or startsWith(mobilePhone,'%2B44 765')&$count=true
英文:

OData protocol supports trim function but not the Graph API.

The request with trim

https://graph.microsoft.com/v1.0/users?$filter=startsWith(trim(mobilePhone),'%2B420')&$count=true
Header: ConsistencyLevel:eventual

will return Request_UnsupportedQuery error code

Only way is to combine all forms

https://graph.microsoft.com/v1.0/users?$filter=startsWith(mobilePhone,'%2B44765') or startsWith(mobilePhone,'%2B44 765')&$count=true

huangapple
  • 本文由 发表于 2023年6月13日 17:31:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76463490.html
匿名

发表评论

匿名网友

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

确定