【问题标题】:Fetchxml How to fetch multiple attributes in a groupby fetch (aggregate)Fetchxml 如何在 groupby fetch 中获取多个属性(聚合)
【发布时间】:2020-08-27 00:57:51
【问题描述】:

我有一个 fetchxml,它工作正常,直到我向 fetch 添加另一个属性。

 <attribute name="ey_b_closed_conversations" alias="isClosed" /> 

这是我添加到 fetch 中的行,现在它不起作用。 以下代码是完整的 fetchxml。

<fetch mapping="logical" version="1.0" aggregate="true" distinct="false"> 
  <entity name="ey_case_branch_callcenter_inquiry">
    <attribute name="ey_s_name" alias="count" aggregate="countcolumn" /> 
    <attribute name="ey_p_action" alias="id" groupby="true" /> 
    <attribute name="ey_b_closed_conversations" alias="isClosed" />  
      <filter>     
     <condition attribute="ey_case_sub_subjectid" operator="eq" value="{9E52CB8E-BEA6-E411-AFFF-0050568C0143}" />
    <condition attribute="statecode" operator="eq" value="0" />       
    </filter>     
  </entity>   
</fetch>

我可以在聚合的 fetchxml 中获取的属性数量是否有任何限制? 如何将我的附加(非聚合)属性添加到 fetch?

【问题讨论】:

    标签: group-by dynamics-crm aggregate dynamics-crm-2011 fetchxml


    【解决方案1】:

    我可以在聚合的 fetchxml 中获取的属性数量是否有任何限制?

    没有。

    如何将我的附加(非聚合)属性添加到 fetch?

    你不能。


    您可能收到此错误:An attribute can not be requested when an aggregate operation has been specified and its neither groupby nor aggregate.

    这类似于 SQL 错误:Column 'xxxx' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

    出现此错误是因为查询中的以下行中没有 groupbyaggregate 属性。

    <attribute name="ey_b_closed_conversations" alias="isClosed" />
    

    参考this community post

    这是因为当您分组时,您只能包含您未分组的属性作为聚合(例如 sum/min/max/count)

    我测试了以下,它工作:

    <fetch mapping="logical" version="1.0" aggregate="true" distinct="false" >
      <entity name="account" >
        <attribute name="name" alias="count" aggregate="countcolumn" />
        <attribute name="telephone2" alias="phone" groupby="true" />
        <attribute name="telephone1" alias="mobile" aggregate="count" />
        <attribute name="accountnumber" alias="number" groupby="true" />
        <filter>
          <condition attribute="statecode" operator="eq" value="0" />
        </filter>
      </entity>
    </fetch>
    

    SQL 等价物:

    SELECT   count(name) AS count,
             count(telephone1) AS mobile,
             telephone2 AS phone,
             accountnumber AS number
    FROM     account
    WHERE    statecode = 0
    GROUP BY telephone2, accountnumber
    

    所以要么这样做:

    <attribute name="ey_b_closed_conversations" alias="isClosed" aggregate="count" />
    

    <attribute name="ey_b_closed_conversations" alias="isClosed" groupby="true" />
    

    【讨论】:

    • 非常感谢,得到所有答案:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-13
    • 2019-03-07
    相关资源
    最近更新 更多