Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Fetch xml - Group by

Posted on by Microsoft Employee

Hi,

I need to grouping result by some attribute,

I tried like on picture below, but without success.

<fetch top="5000" aggregate="true" >
  <entity name="a24_event_journal" >
    <attribute name="a24_journal_type_opt" alias="a24_journal_type_opt" groupby="true" />
    <attribute name="a24_description_txt" alias="a24_description_txt" />
    <link-entity name="campaign" from="campaignid" to="a24_campaign_ref" >
      <attribute name="actualstart" alias="actualstart" />
      <attribute name="actualend" alias="actualend" />
      <attribute name="name" alias="name" />
    </link-entity>
    <link-entity name="account" from="accountid" to="a24_account_ref" alias="account" />
    <link-entity name="contact" from="contactid" to="a24_contact_1_ref" link-type="outer" alias="contact1" />
    <link-entity name="contact" from="contactid" to="a24_contact_2_ref" link-type="outer" alias="contact2" />
    <link-entity name="contact" from="contactid" to="a24_contact_3_ref" link-type="outer" alias="contact3" />
    <link-entity name="task" from="regardingobjectid" to="a24_event_journalid" link-type="outer" alias="task" >
      <attribute name="scheduledend" alias="scheduledend" />
      <attribute name="subject" alias="subject" />
    </link-entity>
  </entity>
</fetch>

Please help me to group by "a24_journal_type_opt" attribute.

Thanks in advance..

Kind regards

Martin

*This post is locked for comments

  • Verified answer
    David Jennaway Profile Picture
    David Jennaway 14,063 on at
    RE: Fetch xml - Group by

    If you use groupby, every other attribute in the output will need an aggregate function, as the results may need to be evaluated across multiple records. You'll need to decide which aggregate function is appropriate for each attribute. In the example below I've used 'min' for the date fields. For the text fields, I've used countcolumn, as there aren't many other useful aggregate functions for text fields.

    <fetch top="5000" aggregate="true" >
      <entity name="a24_event_journal" >
        <attribute name="a24_journal_type_opt" alias="a24_journal_type_opt" groupby="true" />
        <attribute name="a24_description_txt" alias="a24_description_txt" />
        <link-entity name="campaign" from="campaignid" to="a24_campaign_ref" >
          <attribute name="actualstart" alias="actualstart" aggregate="min"/>
          <attribute name="actualend" alias="actualend" aggregate="min"/>
          <attribute name="name" alias="name" aggregate="countcolumn"/>
        </link-entity>
        <link-entity name="account" from="accountid" to="a24_account_ref" alias="account" />
        <link-entity name="contact" from="contactid" to="a24_contact_1_ref" link-type="outer" alias="contact1" />
        <link-entity name="contact" from="contactid" to="a24_contact_2_ref" link-type="outer" alias="contact2" />
        <link-entity name="contact" from="contactid" to="a24_contact_3_ref" link-type="outer" alias="contact3" />
        <link-entity name="task" from="regardingobjectid" to="a24_event_journalid" link-type="outer" alias="task" >
          <attribute name="scheduledend" alias="scheduledend" aggregate="min" />
          <attribute name="subject" alias="subject" aggregate="countcolumn"  />
        </link-entity>
      </entity>
    </fetch>


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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

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