Microsoft Flow – How to make your flows perform better

In this post I’m going through one of the ways to increase the performance of your flows.

In this post I will use the example of counting the number of documents in a SharePoint library.

The bad way

First of all I will start with the Get files action ( you could of course use the REST API and use the Send HTTP Request to SharePoint).

We will now find a number of documents back and we want to count these. So something like this:

That is going to be, ok if you can guarantee only a few documents in a library but as time goes on your flow will not perform for very long as more and more documents are uploaded.

The Impossible

You might have noticed the length function in the Expressions tab so initilizing a varbale with length(body(‘Get_Files’)) could work, but this doesn’t work as the Get files is returning JSON.

All we need to do is create an array!

 

The Speedy Way

The Select function is used for the creation of the array

 

where you can see item() simply use item()?[‘ID’] to select the ID for each item in the JSON returned by the Get files action.

 

Then a length(body(‘Select’))  will give you the number of items in your library:

Now just run your flow and the number of documents is returned:

Performance-wise this makes a big difference. In our first example

There we ran the following actions

  • 1 trigger.
  • 1 Get files
  • 1 Apply to each
  • 8 Increment variable

So that is 11 steps in total.

With the optimized example we only had:

  • 1 trigger
  • 1 get files
  • 1 select
  • 1 Initialize variable (and this isn’t really needed, as you could use the expression within the following steps of your overall flow)

 

Advertisements

2 thoughts on “Microsoft Flow – How to make your flows perform better

  1. Hello,
    Is there a way to make the Select Expression create a nested array? I have a list with a supervisorName column and employeeName column. Each supervisor has many employees. I was hoping Select would provide a way for me to create an array of each supervisor and their respective employees.
    Thanks!

    Like

    1. I had something similar recently. I went for a csv alike approach using the join function.this way I would set people to something like user1;user2;user3 then as I needed to get to the data I would split the text using the split function.

      Like

Please leave a comment or feedback

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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