计算 Dynamics CRM Online 网站中的所有行 api (ODATA)

Counting ALL rows in Dynamics CRM Online web api (ODATA)

是否可以对给定实体中的所有行进行计数,绕过 5000 行限制和页面大小限制?

我不想在一个请求中 return 超过 5000 行,但只想要该给定实体中所有行的计数。

根据 Microsoft 的说法,您不能在请求 URI 中这样做:

The count value does not represent the total number of entities in the system. 

It is limited by the maximum number of entities that can be returned.

我试过这个:

GET [Organization URI]/api/data/v9.0/accounts/?$count=true

还有其他方法吗?

更新:

最新版本 v9.1 具有实现此功能的直接功能 - RetrieveTotalRecordCount

————————————————————————————

不幸的是,我们必须选择一条这条路线来根据限制内的预期结果确定记录数。

1.如果少于 5000,使用这个:(你已经试过了)

GET [Organization URI]/api/data/v9.0/accounts/?$count=true

2。不到5万,用这个:

GET [Organization URI]/api/data/v8.2/accounts?fetchXml=[URI-encoded FetchXML query]

超出限制会报错:AggregateQueryRecordLimit exceeded. Cannot perform this operation.

示例查询:

<fetch version="1.0" mapping="logical" aggregate="true">
  <entity name="account">
    <attribute name="accountid" aggregate="count" alias="count" />
  </entity>
</fetch>

使用 URI 进行浏览器地址栏测试:

[Organization URI]/api/data/v8.2/accounts?fetchXml=%3Cfetch%20version=%221.0%22%20mapping=%22logical%22%20aggregate=%22true%22%3E%3Centity%20name=%22account%22%3E%3Cattribute%20name=%22accountid%22%20aggregate=%22count%22%20alias=%22count%22%20/%3E%3C/entity%3E%3C/fetch%3E

The only way to get around this is to partition the dataset based on some property so that you get smaller subsets of records to aggregate individually.

Read more

3。不得已的方法是遍历 @odata.nextLink 并使用代码变量 (code example to query the next page)

计算每个页面中的记录

您可以尝试 OData's $inlinecount 查询选项。 在查询字符串中仅添加 $inlinecount=allpages 将 return 所有记录,因此在 URI 中添加 $top=1 以仅获取一条记录以及所有记录的计数。

你 URL 看起来会像 /accounts/?$inlinecount=allpages&$top=1

例如,click here 和响应 XML 将计数为 <m:count>11</m:count>

Note: This query option is only supported in OData version 2.0 and above

XrmToolBox 有一个 counting tool 可以帮助解决这个问题。

此外,我们在 MetaTools Inc. 刚刚发布了一个名为 AggX 的在线工具,它可以对 Dynamics 365 Online 组织中的任意数量的记录运行聚合,并且在测试版期间是免费的。

使用函数RetrieveTotalRecordCount:

If you want to retrieve the total number of records for an entity beyond 5000, use the RetrieveTotalRecordCount Function.

您的查询将如下所示:

https://<your api url>/RetrieveTotalRecordCount(EntityNames=['accounts'])

这个有效:

[组织 URI]/api/data/v8.2/accounts?$count