Handling Locked Office Files issue In Power Automate
Handling Locked Office Files issue In Power Automate
Inspired by the workaround described by Pieter Veenstra System Updates in SharePoint from Power Automate using the ValidateUpdateListItem endpoint to help with the locked file issue, this post covers file version creation as well.
File Locked Issue
File lock issues in Power Automate can occur due to:
- The file being opened by a user.
- The file being updated by a Power Automate flow, which may take up to 6 minutes to release the lock. Recently, it has taken even longer, increasing the flow completion time, especially if updates are made in a loop while waiting for the file to be unlocked. For more details, see Speed of SharePoint updates.
File Locked Error
The error within Power Automate flow is
Solution : Use the validateUpdateListItem() REST Endpoint
To resolve the locked file issue, use the Send an HTTP request to SharePoint action to update the file as follows:
site address :
uri: _api/web/lists/getbytitle(‘Controlled Documents’)/items(triggerBody()?[’entity’]?[‘ID’])/validateUpdateListItem()
Headers accept : application/json; odata=verbose Content-Type : application/json; odata=verbose
body
{
"formValues":[{ "FieldName": "ApprovalStatus", "FieldValue": "Pending Approval" },{ "FieldName": "LastReviewDate", "FieldValue":"formatDateTime(utcNow(), 'dd-MM-yyyy')"},
{"FieldName": "Editor",
"FieldValue":"[{'Key':'body('Get_file_properties')?['Editor']?['Claims']'}]"}
],
"bNewDocumentUpdate":false
}
This action updates a file selected by the Power Automate trigger for a selected file
with the status “Pending Approval” and sets LastReviewDate to the current date and time.
Include the Editor , otherwise the file locked error message will be thrown
The bNewDocumentUpdate
parameter determines whether new versions are created. If set to true, no new versions are created. However, for auditing purposes, versions were required even if changes were made by the flow. Therefore, bNewDocumentUpdate
is set to false.
Conclusion
Handling locked files in Power Automate is essential for ensuring smooth flow operations. This workaround not only helps resolve the locked file issue but also ensures that file versions are created and maintained for auditing purposes.