Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Fetch XML count records in link-entity

Posted on by Microsoft Employee

I am trying to write a report that lists our CRM users and the number of times (from the Audit entity) that they have connected between 2 dates.

The link from the systemuser entity to the audit entity, works when I make it select the records from the audit entity, but due to the number of records returned, I just want a count of the audit records.

I can't get the syntax correct for the groupby/count clauses, can anyone see where I've gone wrong.

<fetch distinct="false" no-lock="false" mapping="logical" aggregate="true" >

<entity name="systemuser">
   <attribute name="fullname" groupby='true' />
  
 <filter type='and'>
   <condition attribute='siteid' operator='not-null' />
 <condition attribute='siteid' operator='ne' value='' />
 <condition attribute='isdisabled' operator='eq' value='0' />
</filter>

<link-entity name='audit' from='objectid' to='systemuserid' alias='Audit' aggregate="true" link-type='outer' >
 <attribute name="createdon" aggregate="count" alias="RecC" />
 <filter type='and'>
   <condition attribute='action' operator='eq' value='64'/>
   <condition attribute='createdon' operator='between'>                     

        <value>@StartDate</value>
        <value>@EndDate</value>
    </condition>

</filter>

</link-entity>
</entity>

</fetch>

*This post is locked for comments

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Fetch XML count records in link-entity

    Thanks guys for your suggestions, I never did solve this so I will give these a try.

  • Verified answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Fetch XML count records in link-entity

    Hi Steve,

    Filter condition for date should be like below.

       <filter type="and">
          <condition attribute="createdon" operator="on-or-after" value="2017-08-01" />
          <condition attribute="createdon" operator="on-or-before" value="2018-03-28" />
        </filter>
    


    You can refer below msdn reference to write aggregation and group by.

    https://msdn.microsoft.com/en-us/library/gg309565.aspx

    Hope this helps.

  • Verified answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Fetch XML count records in link-entity

    Hi Steve,

    You can try the tools available in XRM toolbox to build the sysntact/ fetchxml query and also see the outcome.

    www.xrmtoolbox.com/.../Cinteros.Xrm.FetchXmlBuilder

    Hope this helps.

  • Suggested answer
    Abby Kong Profile Picture
    Abby Kong 6 on at
    RE: Fetch XML count records in link-entity

    Hi Steve,

    Tested below fetchxml works, see highlighted the part I changed.

    Also, I'm not sure what kind of date range you are looking at, please beware the record limitation of fetchxml. Read point 9 of this article:

    http://www.kingswaysoft.com/blog/2013/06/18/Limitations-with-CRM-FetchXML

    <fetch distinct='false' no-lock='false' mapping='logical' aggregate='true' >
    <entity name='systemuser'>
       <attribute name='fullname' alias='fullname' groupby='true' />
     <filter type='and'>
       <condition attribute='siteid' operator='not-null' />
     <condition attribute='siteid' operator='ne' value='' />
     <condition attribute='isdisabled' operator='eq' value='0' />
    </filter>
    <link-entity name='audit' from='objectid' to='systemuserid' alias='Audit' aggregate='true' link-type='outer' >
     <attribute name='createdon' aggregate='count' alias='RecC' />
     <filter type='and'>
       <condition attribute='action' operator='eq' value='64'/>
       <condition attribute='createdon' operator='on-or-after' value='2018-01-01'/>
       <condition attribute='createdon' operator='on-or-before' value='2018-03-01'/>
    </filter>
    </link-entity>
    </entity>
    </fetch>


    Regards,
    Abby


  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Fetch XML count records in link-entity

    Thanks, but I had already tried both the answers in the stackoverflow post, neither work for me.

  • Rajkumar Rajaraman Profile Picture
    Rajkumar Rajaraman 18,108 on at

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans