Microsoft Flow – Querying large libraries – Resolved

Today I’m looking at querying libraries using flow. Flow is making this easy as it has an action called Get Files (properties only)Get file (properties only) actionYou specify the site, library and off you go. Easy isn’t it?I hear you say: Where is the pain in that? This is SharePains! We want pain!Well pain you are going to get!First of all have you noticed the default = all in the above action? It is not true! by default this action returns 100 items. Wen you push the results into an apply to each you will see just 100 items returned.I’m going to start by counting the number of items in my Flow. using the Apply to each step:Counting the number of items returns gives 100When you set the limit to 5000 then you will see 5000 items returnedSet the top count to 5000What if your library has more than 5000 documents in it? We all know that the REST API requires indexes on columns to return more than 5000 items.I set the number of items to be returned to 6000.In my flow run I was quite quickly seeing messages like this:retry in get files after 4 retries Flow gives up and I’m starting to get worried that I’m hitting issues similar to the REST API handling 5000 items.4 retries resulting in BadGatewayTime to use my indexes. My document library needs some indices. I tried of could to create an index on the ID column but it isn’t possible to create indices once you have more than 5000 documents.So setting the Filter Query to filter by modification date should sort this out:Setting the top to 6000Ok, I’m really pushing Flow now. I’m still getting 5000 items back but I’m able to query all by 8000 documents. In my case I don’t need all 8000 document to be returned I just need to be able to query all 8000 document and just get a couple of documents returned.So in short, if you didn’t plan the for the number of document to exceed 5000, make sure that you look at the automatically created column indices on your libraries. it might give you an acceptable escape route.Note: When you create an index on a column on a large list you will not know when the index is created, however the index will be created. You just don’t know when. So when you run into issue, create the index and just wait! 

Frequently asked questions

Why did Get files return fewer items than expected?

In the historical test, the default returned 100 items despite the displayed all setting; the author adjusted the action’s limit.

How did the author query a large library?

The example filters by modification date and uses an available column index to query a subset rather than returning every document.

Does indexing guarantee that a large query returns every document?

No. The article reports that its query returned a subset of the larger library, not all documents, and service behaviour may have changed.

Is your business still running on paper trails, sprawling Excel files, or ageing Access databases? There's a better way — and I can show you exactly what it looks like. I'm the Technical Director of Vantage 365, a Microsoft solutions consultancy working with clients across the UK, the Netherlands, and worldwide. For over 30 years I've been turning messy, manual business processes into clean, automated systems that save time, reduce errors, and give teams the visibility they need to make better decisions. SharePains is not just any blog run by a Microsoft MVP. Have you ever used Try-Catch in Power Automate? The original post about Try-Catch in Power Automate can still be found on this site, https://sharepains.com/2018/02/07/try-catch-finally-in-power-automate-flow/ Or have you ever used the Pieter’s method to avoid variables and speed up your flows? https://sharepains.com/2020/03/11/pieters-method-for-advanced-in-flows/ You can contact me using contact@sharepains.com

Related Posts

2 thoughts on “Microsoft Flow – Querying large libraries – Resolved”

  1. Another pain I’ve found with the Get Items action is that there’s a maximum 12 lookup columns allowed in the library (this includes workflow status columns, we’ve got reuseable workflows so there are a few).
    So I’m working on using the new (as of May 2018) action “Send an http request to SharePoint” and “Parse JSON” to get similar results to the Get Items action.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

×