Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

keep getting errors with this fetchxml query

(0) ShareShare
ReportReport
Posted on by 2,409

Hi, I keep getting errors with this query, anything wrong? Error: "an attribute cannot be requested when an aggregate operation has been specified and its groupby nor aggregate. NodeXML: <attribute name ="customerid"/>"

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" top="3" aggregate="true" >
  <entity name="incident" >
    <attribute name="customerid" />
    <attribute name="new_resolutiondate" aggregate="max" />
    <attribute name="title" />
    <attribute name="incidentid" />
    <filter type="and" >
      <condition attribute="statecode" operator="eq" value="1" />
    </filter>
    <link-entity name="account" from="accountid" to="customerid" visible="false" link-type="outer" alias="a_4b5945b8a4a64613afc1ae1d5e6828c7" >
      <attribute name="primarycontactid" />
      <attribute name="new_registrationid" />
      <attribute name="address1_postalcode" />
    </link-entity>
  </entity>
</fetch>


*This post is locked for comments

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: keep getting errors with this fetchxml query

    Use FetchXML tester of XRMTollBox to test any query.

  • Suggested answer
    MSCRM Guru Profile Picture
    MSCRM Guru 600 on at
    RE: keep getting errors with this fetchxml query

    Hi,

    Not sure what you mean by "group", but assuming you want the max resolution date for each customer, you need to remove the other columns from the case entity which shouldn't be in the group by at all which are the incidentid (which will mess up any aggregate query since its always unique) and the title.

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" top="3" aggregate="true" >
      <entity name="incident" >
        <attribute name="customerid" groupby="true" alias="customerid" />
        <attribute name="new_resolutiondate" aggregate="max"  alias="new_resolutiondate"/>
        <filter type="and" >
          <condition attribute="statecode" operator="eq" value="1" />
        </filter>
        <link-entity name="account" from="accountid" to="customerid" visible="false" link-type="outer" alias="a_4b5945b8a4a64613afc1ae1d5e6828c7" >
          <attribute name="primarycontactid" groupby="true" alias="primarycontactid" />
          <attribute name="new_registrationid" groupby="true" alias="new_registrationid"/> 
          <attribute name="address1_postalcode" groupby="true" alias="address1_postalcode"/> 
    </link-entity> 
    </entity> 
    </fetch>

    If you also want to get details of the specific case that had the max(resolution date) you need to run a different query, or get all the data and do the aggregation yourself in LINQ.

    Good luck.

  • sdnd2000 Profile Picture
    sdnd2000 2,409 on at
    RE: keep getting errors with this fetchxml query

    Yes, for each group

  • Gopalan Bhuvanesh Profile Picture
    Gopalan Bhuvanesh 11,401 on at
    RE: keep getting errors with this fetchxml query

    Do you want to get only one record which has the latest new_resolutiondate?

  • sdnd2000 Profile Picture
    sdnd2000 2,409 on at
    RE: keep getting errors with this fetchxml query

    It worked. But it didn't look like what I need. Is that possible to get the max  "new_resolutiondate" field which I have used aggregate max for each group?

  • Verified answer
    Thomas David Dayman Profile Picture
    Thomas David Dayman 11,323 on at
    RE: keep getting errors with this fetchxml query

    I believe you have to groupby your attributes that you are not aggregating.

    I have edited some of your code below:

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" top="3" aggregate="true" >
      <entity name="incident" >
        <attribute name="customerid" groupby="true" alias="customerid" />
        <attribute name="new_resolutiondate" aggregate="max"  alias="new_resolutiondate"/>
        <attribute name="title" groupby="true" alias="title"  />
        <attribute name="incidentid" groupby="true" alias="incidentid" />
        <filter type="and" >
          <condition attribute="statecode" operator="eq" value="1" />
        </filter>
        <link-entity name="account" from="accountid" to="customerid" visible="false" link-type="outer" alias="a_4b5945b8a4a64613afc1ae1d5e6828c7" >
          <attribute name="primarycontactid" groupby="true" alias="primarycontactid" />
          <attribute name="new_registrationid" groupby="true" alias="new_registrationid"/> 
          <attribute name="address1_postalcode" groupby="true" alias="address1_postalcode"/> 
    </link-entity> 
    </entity> 
    </fetch>


  • Chris H @ ISC Profile Picture
    Chris H @ ISC 2 on at
    RE: keep getting errors with this fetchxml query

    I think it doesn't like 'customerid' because it's a field that could be an account or a contact?  Maybe use accountid on the incident, which should have the linked accountid if the case is linked to an account and NOT a contact.

  • sdnd2000 Profile Picture
    sdnd2000 2,409 on at
    RE: keep getting errors with this fetchxml query

    Hi, I removed "top=3", and order by "new_resolutiondate ". still the same error, I have to use aggregate since I want to find the max  new_resolutiondate

  • Gopalan Bhuvanesh Profile Picture
    Gopalan Bhuvanesh 11,401 on at
    RE: keep getting errors with this fetchxml query

    Hi

    What happens when you try as below:

    Put Order by new_resolutiondate (descending) and remove aggregate, as you have Top="3".

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,321 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans