dynamics-crmmicrosoft-dynamicsdynamics-365fetchxml

Dynamics crm fetchxml group by


I would like to have the total number of tasks for each user. For example, John Smith 562, Elsa Taylor 953, etc. I tried this fetchxml, but the result is just the total number of tasks:

<fetch aggregate="true" >
  <entity name="task" >
    <link-entity name="systemuser" from="systemuserid" to="ownerid" >
      <attribute name="fullname" alias="fullname" aggregate="count" />
    </link-entity>
  </entity>
</fetch>

How can I accomplish this?


Solution

  • You need to switch your query around and select (and group by) the systemuser fullname and count the tasks:

    <fetch aggregate="true" >
      <entity name="systemuser" >
        <attribute name="fullname" alias="fullname" groupby="true" />
        <link-entity name="task" from="ownerid" to="systemuserid" link-type="inner" alias="t" >
          <attribute name="activityid" alias="numberoftasks" aggregate="count" />
        </link-entity>
      </entity>
    </fetch>