web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Fetch XML count records in link-entity

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Rajkumar Rajaraman Profile Picture
    on at
  • Community Member Profile Picture
    on at

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

  • Suggested answer
    Abby Kong Profile Picture
    6 on at

    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


  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    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.

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    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
    Community Member Profile Picture
    on at

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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans