Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Unanswered

fectchxml aggregate query not working in Account entity

Posted on by 5

My Account entity data like this:

   ownerid      accountid(PrimaryKey)        new_name

     user1       3E69C24F-FFA8-...              CompanyA

    user1     4E23C24F-FFA8-...              CompanyB

    user2     5T32C24F-FFA8-...              CompanyA

    user3     6G32C24F-FFA8-...        CompanyC

Now,I want use fetchxml aggregate query to get result like this:

   ownerid      accountquantity

    user1        2

    user2        1

    user3        1

But,I got a worng result when I use fectchxml aggregate query by "ownerid".My fetchxml like this:
  string fetchxml = string.Format(@"
                    <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' aggregate='true'>
                      <entity name='account'>
                        <attribute name='ownerid' alias='ownerid' groupby='true' />
                        <attribute name='accountid' alias='countnum' aggregate='count' />
                        <filter type='and'>
                          <condition attribute='new_status' operator='eq' value='10' />
                          <condition attribute='statecode' operator='eq' value='0' />
                        </filter>
                      </entity>
                    </fetch>");

Dynamic CRM version is 8.2.  what's wrong in the fetchxml?

Thanks!

  • jianmin459 Profile Picture
    jianmin459 5 on at
    RE: fectchxml aggregate query not working in Account entity

    Thank you very much !

       I have found the cause of the problem. My Account entity has a plugin step registered in RetrieveMultiple message,and it will change the fetchxml attribute when it runs.

  • RE: fectchxml aggregate query not working in Account entity

    Hy,

    I have tested above fetchXML in my Vanilla and seems to be working fine :-

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" aggregate="true" >
    <entity name="account" >
    <attribute name="ownerid" alias="ownerid" groupby="true" />
    <attribute name="accountid" alias="countnum" aggregate="count" />
    <filter>
    <condition attribute="name" operator="like" value="A%" />
    </filter>
    </entity>
    </fetch>

    Can you please share your code , so that we can have a look.

    Thanks,

    Ankit Sabharwal

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