Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8451559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:16:27+00:00 2026-06-10T11:16:27+00:00

Problem I have a Fetch XML query that has an aggregate count on a

  • 0

Problem

I have a Fetch XML query that has an aggregate count on a linked entity that isn’t behaving as expected. Basically I’m returning a list of courses, and getting a count of how many contacts are currently registered for the course, but even if no one is registered for the course, I’m getting a count of 1 contacts registered. If I register 1 contact, I get a count of 1. If I register 5 contacts, I get a count of 5, so the issue seems to be resolving around not being able to get a count of 0, when there are no related records.

Here is the Fetch XML

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" aggregate="true">
  <entity name="new_coursesection">
    <attribute name="new_termscheduleid" groupby="true" alias="new_termscheduleid" />
    <attribute name="new_termid" groupby="true" alias="new_termid" />
    <attribute name="new_sectionname" groupby="true" alias="new_sectionname" />
    <attribute name="new_name" groupby="true" alias="new_name" />
    <filter type="and">
      <condition attribute="new_courseid" operator="eq" value="{some guid}" />
      <condition attribute="statecode" operator="eq" value="0" />
    </filter>
    <link-entity name="new_contactcoursesection" from="new_coursesectionid" to="new_coursesectionid" alias="new_contactcoursesection1" link-type="outer">
      <attribute name="new_contactcoursesectionid" aggregate="count" alias="coursecount" />
      <filter>
        <condition attribute="statecode" operator="eq" value="0"/>
      </filter>
      <order alias="coursecount" descending="true" />
    </link-entity>
  </entity>
</fetch>

Has anyone encountered this issue and know a work around?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T11:16:28+00:00Added an answer on June 10, 2026 at 11:16 am

    Figured out the issue after looking at the generated SQL with the trace log enabled. Had to change count to countcolumn:

    Broken

    <attribute name="new_contactcoursesectionid" aggregate="count" alias="coursecount" />
    

    Fix

    <attribute name="new_contactcoursesectionid" aggregate="countcolumn" alias="coursecount" />
    

    Although I believe there is a bug in CRM 2011 when dealing with aggregate values of a linked entity in FetchXML. Even though it is marked with an alias, the AliasedValue in the Attribute collection will use the actual CRM name, rather than the aliased one, even though the AttributeCollection’s key will correctly use the aliased name. Weird…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data fetching method that uses jQuery.ajax() to fetch xml files. /*
I have an xml column in my SQL Server database that has records in
i have a problem with willDisplayCell it doesn't stop fetch Xml from the url
I have a problem in mysql. I need to fetch certain sets of records
I've seen that a few instances of this problem have been raised already. However,
Problem: I have a table that prints out vertical but I would like it
Problem: I have a value that is set in $record, for instance 1.69. Then
Problem: I have a string that looks like this: [1=>2,3,4][5=>6,7,8][9=>10,11,12][13=>14,15][16=>17,18] Question: How can you
I have two classes, Test2 and Test3. Test2 has an attribute test3 that is
I have an odd problem that is crashing my app, that I would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.