Tip #1375: Get record count for entities

I need to perform some data… uhm… “augmentation”. Easy as using Power Automate – get all the records, loop through, fudge I mean augment the data. Right? Except there could be more than 100,000 records. Why 100K? That’s the maximum you can get with the List Records action. (Wanted to insert a reference here but that limit does not seem to be documented at all… Oh, well, save it for another tip). In short: I need quickly to find out the total number of records in couple entities. On top of that, those were the entities not exposed outside of their parent entities, like Order Product or Invoice Product.

Even if you are not a developer there are couple Web API methods you can add to your toolbox and RetrieveTotalRecordCount function is one of them.

https://orgname.crmN.dynamics.com/api/data/v9.1/RetrieveTotalRecordCount(EntityNames=['logical_name_1','logical_name_2', ...])

for example:

https://foobar.crm.dynamics.com/api/data/v9.1/RetrieveTotalRecordCount(EntityNames=['salesorder','salesorderdetail','invoice','invoicedetail'])

This is what comes back:

{
  "@odata.context": "https://foobar.crm.dynamics.com/api/data/v9.1/$metadata#Microsoft.Dynamics.CRM.RetrieveTotalRecordCountResponse",
  "EntityRecordCountCollection": {
    "Count": 4,
    "IsReadOnly": false,
    "Keys": [
      "salesorder",
      "salesorderdetail",
      "invoice",
      "invoicedetail"
    ],
    "Values": [
      6679,
      10547,
      17568,
      59618
    ]
  }
}

Nice and easy, right?

Cover photo by Amornthep Srina from Pexels.

Leave a Reply

Your email address will not be published. Required fields are marked *