API $扩展和计数

问题描述 投票:1回答:1

是否可以使用$expand但不返回对象集合,只返回对象的数量?

例如,在单个WebApi调用中获取帐户及其注释计数

我尝试了一些事情。

  • 明显的尝试:accounts(6CDEEB72-2AC8-E711-A825-000D3AE0A7F8)?$select=name&$expand=Account_Annotation($count=true)返回所有注释的所有字段但不计算任何内容。
  • 接下来我试过accounts(6CDEEB72-2AC8-E711-A825-000D3AE0A7F8)?$select=name&$expand=Account_Annotation($select=annotationid&$count=true)返回一个错误:“找到一个不平衡的括号表达式”。我认为这与$expand中的&符号有关
  • 我发现一个非crm博客说这可以用一个解决;但当我尝试accounts(6CDEEB72-2AC8-E711-A825-000D3AE0A7F8)?$select=name&$expand=Account_Annotation($select=annotationid;$count=true)它没有给出错误,但$count指令似乎被忽略
  • accounts(6CDEEB72-2AC8-E711-A825-000D3AE0A7F8)?$select=name&$count=Account_Annotation($select=annotationid)的疯狂尝试返回“非有效计数”错误

我猜这不是一个有效的组合,但我想我会发布在这里以防其他人成功实现这一点。

dynamics-crm-365 dynamics-crm-webapi
1个回答
0
投票

我得到了这个工作,但我不确定它是你正在寻找什么,它只有在扩展之前我把它计数时才有效:

api/data/v9.0/cmnt_salesexample?
$select=endcustomeraccountid&$count=true&$expand=endcustomerid($select=accountid)

输出:

{
"@odata.context": "https://xyz",
"@odata.count": 5000,
"value": [
 {
  "@odata.etag": "W/\"3560581422\"",
  "endcustomerid": "54321"
},
{
  "@odata.etag": "W/\"3510396844\"",
  "endcustomerid": "12345"  
},
...
© www.soinside.com 2019 - 2024. All rights reserved.