
How to Update Locked SharePoint Files Without Loops or User Headaches
The Hidden Workflow Killer: Locked Files in SharePoint
Imagine you have created a Power Automate workflow for a document approval process that updates a status property of the document to keep end users informed. The workflow operates smoothly until you encounter failures, with an error message stating, “The file
This is a common issue encountered in workflows that update file metadata while users have the file open or during co-authoring. Without proper error handling, users may not even realize that the workflow has failed, which can lead to confusion and increased support requests to resolve the workflow problem.
A common solution to this problem involves checking whether the file is locked and repeatedly attempting to update it until the lock is released.
In this post, we will explore a more practical approach. Instead of waiting for the file lock to be released, we can detect the lock, extract the source control lock ID, and use it to update the file without any user intervention, even when the file is in use.
The Waiting Game: Why Do Until Loops Leave Everyone Hanging
One workaround for a locked SharePoint file in Power Automate is to use a Do Until
loop. The concept is straightforward: check if the file is locked, and if it is, use a delay action to wait before checking again. Repeat this process until the file becomes available. While it may not be the most elegant solution, it effectively gets the job done—at least sometimes.
Here is how this approach may look.
This process can be improved by identifying the user who has locked the file and sending them a notification to close it, allowing the workflow to continue. While this approach enhances the system, it still requires user intervention for the workflow to proceed.
In practice, this approach can be clunky. By default, it runs silently in the background and continues to loop without providing feedback to users. From their perspective, the workflow is broken. Users may attempt to retry the action, submit duplicate requests, or contact the workflow owner. When, in reality, the workflow is functioning as intended, it is simply waiting for the file to become available.
Even if notifications are sent to the user who has the file locked, the process still relies on that user to take action before it can proceed. If the user ignores the alert, is away or is out of the office, the process stalls. This type of automated update to file metadata should not depend on user action to function correctly.
The Upgrade: Skip the Wait and Update Locked Files Instantly
There is a more effective way to manage locked files without needing to retry failed updates or alert users to close their documents. Instead of waiting for SharePoint to release the lock, we can leverage some lesser-known features and properties of the files.
The key component of this approach is the LockedByUser
file property. We can send an HTTP request to SharePoint using the lockedByUser
endpoint to determine if the file is locked and by whom. More importantly, SharePoint also maintains a source control lock ID that can be used to override the lock in specific scenarios.
The process operates as follows: The workflow first checks if the file is locked by inspecting the lockedByUser
response. If the file is locked, the workflow extracts the lock ID and then updates the file by passing the lock ID to SharePoint. If the file is not locked, it is updated as usual.
This method allows users to bypass waiting on the workflow. The file metadata is updated seamlessly, and the workflow moves to its subsequent actions.
Step-by-Step Guide to Implementing the New Approach
This method may seem technical, and while it is more complex than the Do until
loop workaround, it is more straightforward than you might think.
Here is the workflow overview.

Get the file properties
The workflow starts by using the Get file properties
action to retrieve all the properties of the file that triggered the workflow. We set the Site Address
and Library Name
and use dynamic content to select the ID
from the selected file trigger.

Get lockedByUser Property
To retrieve the lockedByUser
property value, we use the Send an HTTP request to SharePoint
action. In this action, we set the Site Address
to our SharePoint site and set the Method
to GET. For the Uri
, we use:
_api/web/lists('')/items('')/File/lockedByUser
Finding the
for this action can be challenging. However, since we already have the Get file properties
action, we can use Power Automate’s Code view to locate the required value.

Then, we use dynamic content for the
to add the required ID value. Lastly, under Advanced parameters, we set the headers as follows:
{
"Accept": "application/json;odata=nometadata",
"Content-Type": "application/json;odata=nometadata"
}

Check the lockedByUser Response
When the file is locked, the response body
of the HTTP request GET lockedByUser
action indicates who has the file locked.
{
"Id": 11,
"IsHiddenInUI": false,
"LoginName": "i:0#.f|membership| ",
"Title": " ",
"PrincipalType": 1,
"Email": " ",
"Expiration": "",
"IsEmailAuthenticationGuestUser": false,
"IsShareByEmailGuestUser": false,
"IsSiteAdmin": false,
"UserId": {
"NameId": " ",
"NameIdIssuer": " "
},
"UserPrincipalName": " "
}
The body
contains the following information when the file is not locked.
{
"odata.null": true
}
We use the odata.null
property value in the Condition
flow control to check if the file is locked.

We utilize the following function to include odata.null
in the condition.
body('HTTP_request_GET_lockedByUser')?['odata.null']
Locked File Branch
If odata.null
is not equal to true
, our file is locked, and the workflow progresses down the True
branch. We first need to obtain the source control lock ID to update the locked file.
You might be wondering where to find the lock ID. To view a list of file properties available within our workflow—beyond the basic properties returned by the Get file properties
action—we add another Send an HTTP request to SharePoint
action.
First, set the Site Address
to our SharePoint site and choose “GET” as the Method
. Then, use the following URI:
_api/web/lists('')/items('')/File/Properties
*See the Get lockedByUser Property section to located and
We can proceed to run a test of our workflow to examine the raw output of this request. In the output, we will see a list of available properties. The specific property we need is the value of vti_x005f_sourcecontrollockid
.
Next, we will update the URI to select this particular property value.
_api/web/lists('')/items('')/File/Properties?$select=vti_x005f_sourcecontrollockid

Once we have the required lock ID, we use another Send HTTP request to SharePoint
action to perform the update. We set the Site Address
to our SharePoint site and choose POST as the Method
. Then, under the Advanced parameters, we select Show all
to provide the necessary headers and body values.
For the Headers parameter, we use the following:
{
"Accept": "application/json;odata=nometadata",
"Content-Type": "application/json;odata=nometadata"
}
For the Body parameter, we will use:
{
"formValues": [
{
"FieldName": "ApprovalStatus",
"FieldValue": "In Process (Updated Locked File)"
}
],
"sharedLockId": "body('HTTP_request_GET_sourcecontrollockid')?['vti_x005f_sourcecontrollockid']",
"bNewDocumentUpdate": true
}
We dynamically utilize the lock ID within the Body parameter using this function.
body('HTTP_request_GET_sourcecontrollockid')?['vti_x005f_sourcecontrollockid']

Unlocked File Branch
If the file is not locked, we use the Send a HTTP request to SharePoint
action to update the file. We configure the action the same way as the HTTP request used for the locked file, with the only difference being the body parameter.
Since the file is not locked, we do not include the sharedLockId
property in the body parameter.
{
"formValues": [
{
"FieldName": "ApprovalStatus",
"FieldValue": "In Process (Updated Locked File)"
}
],
"bNewDocumentUpdate": true
}

Here is the workflow in action.

Continue the workflow with any Additional Actions
Once the update to the file metadata is complete, the workflow continues as usual. The file is updated directly, regardless of whether it is locked.
Although this approach requires some initial setup, once implemented, the workflow becomes more resilient and less dependent on unpredictable user behavior.
Wrapping Up
Locked SharePoint files can disrupt our Power Automate workflows, causing updates to stall and confusing users. Common fixes, such as using Do Until
loops and notifications rely heavily on timing and user intervention.
The approach outlined here first checks if the file is locked. If it is, the method extracts the lock ID and sends an HTTP request to update the file with no retries or end-user intervention.
This workflow makes our workflow more efficient and reliable, enabling true automation without requiring any user action for the workflow to proceed.
Curious about the TRY Update document properties
scope within the workflow?

Check out this post focused on Power Automate error handling and notifications.

Thank you for reading! Stay curious, and until next time, happy learning.

And, remember, as Albert Einstein once said, “Anyone who has never made a mistake has never tried anything new.” So, don’t be afraid of making mistakes, practice makes perfect. Continuously experiment, explore, and challenge yourself with real-world scenarios.
If this sparked your curiosity, keep that spark alive and check back frequently. Better yet, be sure not to miss a post by subscribing! With each new post comes an opportunity to learn something new.