1

我正在尝试在 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>

有什么建议么?

谢谢。

4

3 回答 3

0

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

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

    <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 的条件

于 2014-01-22T16:48:06.857 回答
0

你想要做的需要一个子查询。这是CRM 不支持的。

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

如果您只是尝试使用 SDK 拉回数据,则可以在客户端执行子查询。

为什么 Max Aggregate 不起作用

如果您想要获得最大值的列是一个数字,您可以使用聚合,但聚合函数 AVG、MIN、MAX 或 SUM 只能应用于整数、浮点、金钱、大整数或小数类型的属性.

如果您尝试运行此查询,那就是错误:

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);
于 2014-01-15T20:50:31.000 回答
0

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

于 2014-01-17T02:36:40.720 回答