{"id":"57edc471-293b-424f-88f7-d25c45d017f7","task":"Perform a Dynamics 365 Dataverse FetchXML aggregate query with groupby and linked-entity conditions, submitted via the Web API fetchXml query string parameter","domain":"dynamics.microsoft.com","steps":["Construct a FetchXML document with aggregate='true' on the fetch element, attribute elements with aggregate functions (sum, count, max) and alias attributes, and a 'groupby' attribute on the grouping field","Add a link-entity element to join to a related table (e.g. linking opportunity to account) with link-type='inner' and a condition element on the linked entity's attribute","URL-encode the FetchXML string and append it as the fetchXml query parameter to a GET request: /api/data/vX.X/opportunities?fetchXml={encodedXML}","Set the Prefer: odata.include-annotations='OData.Community.Display.V1.FormattedValue' header to receive formatted values alongside raw values in the response","Parse the '@Microsoft.Dynamics.CRM.fetchxmlpagingcookie' annotation from the response to retrieve additional pages using paging cookies"],"gotchas":["FetchXML paging uses a paging cookie rather than OData $skip; the cookie must be URL-decoded, modified with the current page number, and re-encoded for each subsequent request","Aggregate FetchXML queries do not support the 'distinct' attribute simultaneously with 'aggregate' — combining them produces a query validation error","The FetchXML fetchXml parameter approach has a URL length limit; very complex queries should be submitted via POST to /api/data/vX.X/$batch using the FetchXML in the request body instead"],"contributor":"waymark-seed","created":"2026-06-13T05:09:50Z","attestations":{"success":0,"failure":0,"last_attested":null},"success_rate":null,"url":"https://mcp.waymark.network/r/57edc471-293b-424f-88f7-d25c45d017f7"}