Thursday, 12 March 2020

Returning items from Common Data Service (CDS) using Powershell and paging

Having recently waded into the uncharted (by me) waters of CRM and CDS APIs, it's taken some time to get up to speed.

Seems like not many people are using Powershell to work with CDS data.  I found a very helpful post by Ignas Labinas (thanks heaps Ignas) which got me well started.

This was all fine until I found I needed to return more than 5,000 records.

I was using the GetEntityDataByFetchSearchEC method, but I soon discovered that FetchXML will only return 5,000 records at a time.

So I have offered 2 solutions, the first is what to do if your returned data is never ever going to be likely to exceed 5,000 records.

The second solution, although a little more complex, will demonstrate how to use paging to return more than 5,000 records.

Just to be safe, I don't know why you wouldn't just use the second option under all circumstances.

If there is no chance of ever needing to return more than 5,000 Records

Here is the WORKING Powershell function, for up to 5,000 records:


If there is any chance that you might need to return more than 5,000 records

Once I realized I needed to return more than 5,000 records, I needed to figure out how this paging caper worked.

There were lots of .NET samples on the Internet that I mucked around with, until, with a bit of debugging and jiggery-pokery, I managed to convert this .NET method into something that works in Powershell.
I hope this helps someone out there.

No comments:

Post a Comment