按相关实体中的记录数过滤 FetchXML 请求

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

在 Microsoft Dynamics/Dataverse 中,我尝试在与 1:M 关系中的另一个实体相关的实体上编写 FetchXML 请求。我希望它检索与 3 个或更多子记录相关的父记录并忽略其余记录。这可以吗?

我拥有的是:

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
<entity name="quote">
<filter type="and">
<condition attribute="statecode" operator="eq" value="0" />
</filter>
<link-entity name="linked_entity" from="name" to="someid" link-type="outer" />
<filter type="and">
<condition attribute="trefor_kundetype" operator="eq" value="402180000" />
</filter>
</link-entity>
</entity>
</fetch>

我一直在研究聚合函数,但这只会返回总记录数。这可以做到吗?如果可以的话我该如何进行?

dynamics-crm fetchxml dataverse
1个回答
0
投票

看起来您正在尝试执行这样的查询(但使用类似having语句的内容):

<fetch aggregate='true'>
  <entity name='account'>
    <attribute name='name' alias='account_name' groupby='true' />
    <link-entity name='contact' from='parentcustomerid' to='accountid'>
      <attribute name='contactid' alias='no_of_persons' aggregate='count' />
    </link-entity>
  </entity>
</fetch>

不幸的是 fetch xml 不支持有语句 - 即使使用上面的简单查询,您也会遇到以下问题: “超出 AggregateQueryRecordLimit。无法执行此操作。”

我认为最好的方法是在父实体上创建一个汇总字段(计算子项目)。

https://learn.microsoft.com/en-us/dynamics365/customerengagement/on-premises/customize/define-rollup-fields?view=op-9-1

然后,您可以将此汇总字段作为 CRM 中的普通字段进行筛选。

© www.soinside.com 2019 - 2024. All rights reserved.