Skip to main content

In this blog post, HSD Senior Technical Consultant – Ashley Fonseca explains how he implemented a different way to run a record count using an API in Dynamics 365.

If there is a requirement to get record counts for an entity using API then there is RetrieveTotalRecordCount function available. Previous developers were using fetch xml and Power Automate connector to get all records for an entity, but these methods have their limitation.

 

  • Fetch xml can only retrieve 5000 records at the time
  • Power Automate connector is more generous and allow to retrieve maximum 100,000 records assuming you are on top tier D365 plan
  • There are some hidden entities like invoice product which are only accessible thru their parent entity.

Using RetrieveTotalRecordCount function we can easily make an API call to get record count. You can even request a record count of multiple entities in one call.

Parameter

EntityNames: The logical names of the entities to include in the query.

Return Type

RetrieveTotalRecordCountResponse: The RetrieveTotalRecordCount function returns the following value.

Below is the example of an API call

Request to get number of records for Account entity

 

https://{orgname}.crm6.dynamics.com/api/data/v9.1/RetrieveTotalRecordCount(EntityNames=['account’])

Request to get number of records for Account, Contact and Incident

 

https://{orgname}.crm6.dynamics.com/api/data/v9.1/RetrieveTotalRecordCount(EntityNames=['account’,'contact','incident'])

Below is the RetrieveTotalRecordCountResponse 

 

{   
"@odata.context":"https://ashtrial.crm6.dynamics.com/api/data/v9.1/$metadata#Microsoft.Dynamics.CRM.RetrieveTotalRecordCountResponse",
   "EntityRecordCountCollection":{
      "Count":3,
      "IsReadOnly":false,
      "Keys":[
         "account",
         "contact",
         "incident"
      ],
      "Values":[
         108,
         230,
         43
      ]
   }
}

If you or your organisation needs some guidance or advice on Dynamics 365, our dedicated Dynamics 365 practice is available to help. If you would like to chat to one of the team, please click here and we’ll be in touch!

 

Be sure to keep up to date with all of HSD‘s news and content here and on our LinkedIn.