Have you ever struggled to handle file locks in SharePoint when you are running your flows?
File locks and actions in Power Automate
Power Automate’s actions that deal with documents in SharePoint, will have to deal with the same issues that users may deal with, however users have the SharePoint UI that will help them. In flows you will need to deal with it!
In SharePoint there are a number of file locks that may happen:
- A user checks a file out
- Another user checks the file out
- A System Account checks a file out (this can happen when you declare a file as a record)
- A user locks the document by opening a file
What happens when a file is locked?
First of all, what happens when a file is locked in SharePoint and a flow tries to update properties?
The request will fail:
When a document is locked (or open by a user in a browser or client app) for editing then you will receive the following:
The file \”https://pieterveenstramvp.sharepoint.com/Shared Documents/Document3.docx\” is checked out for editing by i:0#.f|membership|testuser@pieterveenstr.
The file \”https://pieterveenstramvp.sharepoint.com/Shared Documents/Document.docx\” is checked out for editing by SHAREPOINT\\system.
Get the Checked Out User
To get the checked out user you can simply look at the document properties on the library:
This can be collected using the following REST API call:
Get the Locked By User
Once you have identified your steps that are potentially affected by document locks, you might want to build retry steps in your flows. Please have a look at the Flow Retrying Pattern for more details