【问题标题】:CRM 2011 FetchXml to pull list accounts and display only most recent activity datesCRM 2011 FetchXml 提取列表帐户并仅显示最近的活动日期
【发布时间】:2014-02-04 11:49:57
【问题描述】:

我正在尝试在 crm 2011 上的 fetchxml 中创建一个显示帐户名称列表的报告,并且在同一行中仅显示该帐户最近活动的日期。

所以

报告应该看起来像

Account1, Date of most recent activity for Account 1
Account2, Date of most recent activity for Account 2
Account3, Date of most recent activity for Account 3

我有一个提取查询可以提取正确的数据,但它会为帐户的每个活动提取一行,而不仅仅是最新的活动。

看起来像

Account1, Date of most recent activity for Account 1
Account1, Date of other activity  for Account 1
Account2, Date of most recent activity for Account 2
Account2, Date of other activity for Account 2
Account3, Date of most recent activity for Account 3

这是我的收获

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" aggregate="false">
    <entity name="<accountentityname>"
        <attribute name="<accountname>" />
        <link-entity name="activity" from="<regardingaccoutnfield>" to="<account field>" visible="false" link-type="outer"> 
            <attribute name="<date of activity>"  />
        </link-entity>
    </entity>
</fetch>

有什么建议吗?

谢谢。

【问题讨论】:

    标签: dynamics-crm-2011 crm fetchxml


    【解决方案1】:

    您可以对日期进行排序并仅返回第一条记录!

    对帐户进行查询,然后为每个帐户返回一个并使用以下内容:

        <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
          <entity name="activitypointer">
            <attribute name="scheduledstart" />
            <order attribute="scheduledstart" descending="true" />
            <filter type="and">
              <condition attribute="scheduledstart" operator="not-null" />
            </filter>
          </entity>
        </fetch>
    

    或类似的查询表达式:

    QueryExpression query = new QueryExpression("activitypointer");
                                query.ColumnSet.AddColumns("scheduledstart");
                                query.AddOrder("scheduledstart", OrderType.Descending);
                                EntityCollection results = service.RetrieveMultiple(query);
    

    然后是这样的:

    (DateTime)(((Entity)results.Entities.First()).Attributes["scheduledstart"]);
    

    添加相关字段等于 for each 循环范围内的 account.id 的条件

    【讨论】:

      【解决方案2】:

      您想要做的事情需要一个子查询。这是CRM does not support 的东西。

      如果您不使用 CRM Online,只需使用 SQL 而不是 FetchXml 执行标准 SSRS 查询。

      如果你只是想用 SDK 拉回数据,你可以在客户端执行子查询。

      为什么 Max Aggregate 不起作用

      如果您想要获取最大值的列是一个数字,您可以使用聚合,但聚合函数 AVG、MIN、MAX 或 SUM 只能应用于 integer、float、money、bigint 类型的属性, 或小数。

      如果您尝试运行此查询,则会出现以下错误:

      var xml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true' aggregate='true'>
        <entity name='contact'>
          <attribute name='fullname' alias='name' groupby='true'   />
          <attribute name='contactid' alias='id' groupby='true'  />
          <link-entity name='activitypointer' from='regardingobjectid' to='contactid' alias='ad' link-type='outer'>
            <attribute name='createdon' alias='createdon_max' aggregate='max' /> 
            <filter type='and'>
              <condition attribute='createdon' operator='not-null' />
            </filter>
          </link-entity>
        </entity>
      </fetch>";
      
      EntityCollection fetchResult = service.RetrieveMultiple(new FetchExpression(xml);
      

      【讨论】:

      • maxaggregate attribute 在这里有用吗?
      • 我不是 fetchxml 专家,但如果您知道回答它所需的 fetch,请执行(我可能有一天需要它!)
      【解决方案3】:

      不确定maxaggregate 属性是否适用于日期时间,但如果适用,可能会起作用

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-05-08
        • 2011-11-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多