Power Community

Power Community

A scheduled flow that locks an app

Earlier this week I was asked on the chat how to handle scheduled flows that need to lock an app in Power Apps while the flow is running.

Scheduled flows

First of all it is important to realize that scheduled flows are not connected to the app in any kind of way. Therefore there isn’t a way to chat back to the app from the scheduled flow.

In this case the problem to solve was the disabling of a button, while the scheduled flow is running.

So for example, this scheduled flow could import some data into your tables, during this process you don’t any of your users to update any records. Then you will need to find a way to lock those users temporarily out of the app.

Creating the lock table

We will first need a data source that can control the lock for us. I’m going to create a table in Dataverse. But you could probably try the same with SharePoint lists or other data sources. However, If you use SharePoint you might find that throttling issues will occur.

I created a locks table and added a column Locked. This column is a Yes/No column. When it is set to Yes, then the app will be locked otherwise the app will be unlocked.

Creating a lock table

Once the table is available, I created one record. Set the Name to Pause This app and the Locked value to No.

Creating a lock record

Creating an app

Time to create the app.

I’ve added a giant button that does something and then I set the display mode to

            Name = "Pause This app"
    ) = "No",
Code to lock an app

Creating the scheduled flow

My flow just has 5 steps, but the Delay action can be replaced by anything that you need the flow to do of course.

A scheduled flow locking the app

In the Update a row – Lock action I’m setting Locked to Yes, sot that my app will lock.

Write the lock

However the app will never lock. To make the app lock we could add a Timer that is scheduled to run every 1 second. Running the following line of code.


This will now lock my app.

A locked app.

Named Formulas

Would the same solution with named formulas be any better? Well named formulas still don’t refresh the data sources either. It would be nice if Power Apps could trigger a data refresh (or preferably a data merge) when a table is updated, but unfortunately that isn’t an option yet.

Some final thoughts

If you have an app that is used by many people and it is used all the time, then there could be some performance issues if you created many locks. The solution here reads the lock every second. So that means reading the locks 60 times per minutes for every user that is logged in.

This post was originally published on this site

- Advertisement -spot_img


Please enter your comment!
Please enter your name here

- Advertisement - Advertisement

Latest News

Adjusting the time zone in Power BI DAX – Quick Tip

Hi Folks, Here is the use case, I was actually pulling data from Model Driven App. As I was testing...

More Articles Like This

- Advertisement -spot_img