web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Power Automate Handlin...
Power Automate
Answered

Power Automate Handling - Document is locked for shared use by user

(1) ShareShare
ReportReport
Posted on by 85

Hi All,

 

I have created a simple approval workflow that updates the Document's status column as it goes through the different stages (pending, approved or rejected) of approval. 

Occasionally, the workflow fails (while updating the status - pending in this example) with an error saying the documents is locked for shared use by a user. I understand this may happen if the user kept the document still open or did not close it properly.

 

My question is what is the best way to handle such scenarios. Can anyone with similar experience share your ideas please ?

 

workflow error.png

Categories:
I have the same question (0)
  • Paulie78 Profile Picture
    8,422 Moderator on at

    Like this...

    https://ibb.co/1ZTgLV2 (Image link because I find the viewer on here so annoying!

    Wait-Until-File-Is-Not-Locked.png

    Code on the if expression is:

    if(equals(outputs('Update_file_properties')?['body']?['status'],400), true, false)

    Basically it checks if the error response was 400, which is what it gives when the file is locked for editing and waits for it to become available.

     

    I just tried it out and it resumed after the file was closed.

     

    Let me know how you get on.

     

    If I answered your question Accept it as a solution ✔️ 

    If I helped you out, please give me some Kudos 👍

    Thanks 😙

     

  • Paulie78 Profile Picture
    8,422 Moderator on at

    Slight update, change the last step to look like this:

    Wait-Until-File-Is-Not-Locked-Delay.png

    This will change the delay to only 1 second if the file is not locked and make it 90 seconds if it is.

  • Verified answer
    imran7799 Profile Picture
    85 on at

    @Paulie78 : Thanks for your response.

    I also found this article which talks about this issue

    https://sharepains.com/2019/09/26/file-locks-sharepoint-power-automate/

    Basically he suggests to send HTTP Request to check if the file is locked or not and if locked, wait until it gets unlocked.

     

    The API suggest in this article has been deprecated. The new API is this
    /_api/Web/GetFileByServerRelativePath(decodedurl='Site relative URL of the document')/LockedByUser

  • Paulie78 Profile Picture
    8,422 Moderator on at

    No worries, that is useful to know. Glad you sorted it.

  • rofei Profile Picture
    4 on at

    I made a community account on here purely so I could thank you for this solution.  You're amazing, thank you so much!!!

  • FabvE Profile Picture
    79 on at

    I have the same problem with a locked file.

    My problem is that the file is updated via Power Automate at 5 AM. When I try to rerun the flow at noon the file is still locked. Only the Flow 24h later is able to update the file.

     

    Is there a way to unlock the file instead of waiting?

  • CURIOUSUSER Profile Picture
    on at

    I am also interested in learning how to force the file to be unlocked so the move can happen more quickly. I have a flow that is moving a file between folders to keep it organized while the flow is processing, but it is taking 6+ minutes each time the file needs to be moved which is inefficient.


    Any ideas?

  • PritishT Profile Picture
    47 on at

    I too am facing the same issue while moving the file to different folder after processing. Any updates

    PritishT_0-1707719292630.png

     

  • scape303 Profile Picture
    4 on at

    not sure if this will help any specific case, but i was able to mostly resolve my issue by adding a check out file action before editing actions and then a check in afterwards.  seems to help a lot, and i haven't had any locked issues in my case after i made that revision.

     

    hope this helps someone with a similar battle.

  • MM-01081405-0 Profile Picture
    2 on at
    Helpful note:
    Case -
    1. PowerShell script creates >15k word.docx files from .csv file data and save to local folder synced to SharePoint document library.
    2. Flow triggers when file is created in the SharePoint document library.
    2.1     Flow creates the same file in different SharePoint site. (Always succeeded)
    2.2     Flow moves the file created in (1) to a different folder in same SharePoint site.
     
    The problem presented on (2.2) telling me the file was locked and Flow failed.
    The problem was inconsistent with a few (not necessarily sequential) successful flow runs and many failed flow runs.
     
    Implemented the solution found here with no real success. The solution works. But, only if the file ever becomes unlocked, causes long flow runs, excessive network load, and the need to 'manage' the instances where the flow times out without successfully moving the .docx file.
     
    After many hours of failure and on the next morning, I closed Visual Studio, reopened to run as administrator, and ran the same script again.
     
    EUREKA! 100% success rate.
     
    Decided to comment here because, in all of my hours and hours of researching, not a single mention of such a simple step. Could be unique to my situation but worth a try for someone with similar issues.
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 503 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 321 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard