Search code examples
odatadynamics-crmcrmdynamics-crm-2016dynamics-crm-webapi

Returning count for an odata query


If I have a query such as:

http://myCRMOrg/api/data/v8.1/accounts?$filter=_chr_accountstatusid_value%20eq%2079A024B5-3D7C-E211-8B29-00155DC86B6F%20and%20accountid%20eq%20e929baaf-483b-e711-9425-00155dc0d345&$count=true

Please notice that I am specifying $count=true

It will return:

{
  "@odata.context":"http://myCRMORG/api/data/v8.1/$metadata#accounts","@odata.count":1,"value":[
    {
      "@odata.etag":"W/\"1812635\"","
      //100 fields and lots of data
    }
  ]
}

How can we reconstruct this query to simply return 1?


Solution

  • I had same issue. What I did is I added count before filter and it worked. Example:

    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts/$count/?$select=accountid&$filter=accountid%20eq%20D1C4CD52-1E51-E711-8122-6C3BE5B3B698&", true);