none
How to lock the document when document is open in sharepoint online RRS feed

  • Question

  • Hi All,

    When a document is uploaded in SharePoint document library .

    If it is open online how to lock the document is it possible to lock the document by using workflow.

    Please help me.

    Thank you,

    Sowjanya.

    Thursday, October 24, 2019 1:20 AM

Answers

All replies

  • Hi Sowjanya,

    I am afraid that we cannot achieve it by workflow because the workflow cannot be triggered when opening the document online.

    The workaround for the issue, you could go to library settings->Versioning settings->in the “Require Check Out” section, select “Yes” for “Require documents to be checked out before they can be edited?”.

    Other users cannot edit the document when one user is editing the document.

    But other users still can open and view the document.

    Best regards,

    Sara Fan


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Thursday, October 24, 2019 7:15 AM
    Moderator
  • Hi Sara,

    That true workflow can not trigger when document is online its not declare as a record.

    My requirement is multiple user should update the document .

    Is there any other solution to achieve other than workflow.

    Thank you,

    Sowjanya.

    Thursday, October 24, 2019 3:20 PM
  • Hi Sowjanya,

    Your question is quite not clear :-) in your initial post you want to lock the document and in your subsequent reply to Sara you want multiple users to update the document - if we do not anything I mean by OOB it is enabled which is called co-authoring feature. And if you are looking for when first user open the document other user can only view that document, this is quite logical and what Sara has replied is correct for this to achieve. 


    Thanks&Regards,

    Habibur Rahaman

    MCSA,MCP,MCTS

    My Certificates

    Note: If you feel the proposed answer is helpful, please mark as so or if this answered your question,please mark as answer.

    Thursday, October 24, 2019 5:39 PM
  • Hi Rahaman,

    My requirement is when we upload the document multiple users will update the document i enabled co-authoring feature for that its working fine .

    After that after 3 days it should lock the document i am using worklfow to do that .

    please find the workflow screen shot

    This workflow is working when document is closed after updating the document.

    My questions is if they forget to close the document "Declare the item as a record is not working"

    still they are able to update the document.

    I didnt see the lock sign .

    please suggest me how to lock the document if still it is open .

    Thank you,

    Sowjanya.

    Thursday, October 24, 2019 7:30 PM
  • Hi Sowjanya,

    Thanks for explaining I understand now. You can write another workflow to check if any documents are approved but not closed - then that new workflow will close that document - then your current existing workflow will continue to work as expected.

    Approaches:

    1. If you have nintex - you can trigger the new workflow conditionally like if document is approved but not closed then only trigger the workflow and there find the items those are not closed and then update the metadata as closed for those document - thru this new workflow.

     or

    1. You may write a small powershell script which will loop thru the your all documents and find the document which is not closed - then your PS code will close the document programmatically - this powershell code you can configure in windows task scheduler as job  which will execute periodically as per the configuration. 

    Thanks&Regards,

    Habibur Rahaman

    MCSA,MCP,MCTS

    My Certificates

    Note: If you feel the proposed answer is helpful, please mark as so or if this answered your question,please mark as answer.


    Friday, October 25, 2019 7:20 AM
  • Hi Rahaman,

    Thank you for quick reply.

    Is there any reference site for this .

    please let me know.

    Thank you,

    Sowjanya.

    Friday, October 25, 2019 2:11 PM
  • Hi Sowjanya,

    There is no references for the approaches - this is my thought by looking at your scenario. However, there are multiple PowerShell script using that we can read the document library items and update some specific metadata based on the condition inside the for each loop.

    Example:

    Client Side CSOM complete working code:

    $SiteURL= "https://your site url/" $ListName="TestDocumentLibrary" $UserName = "Yourusername@sharepoint.com" $Password = "Your password" $SecurePassword= $Password | ConvertTo-SecureString -AsPlainText -Force $BatchSize =1000 #Setup the Context $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL) $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword) #Get the List $List = $Ctx.Web.Lists.GetByTitle($ListName) $Ctx.Load($List) $Ctx.ExecuteQuery() $emptyString = "" #Define CAML Query to get Files from the list in batches $Query = New-Object Microsoft.SharePoint.Client.CamlQuery $Query.ViewXml = "@ <View Scope='RecursiveAll'> <Query> <OrderBy><FieldRef Name='ID' Ascending='True'/></OrderBy> </Query> <RowLimit>$BatchSize</RowLimit> </View>" $count =0 Do { $ListItems = $List.GetItems($Query) $Ctx.Load($ListItems) $Ctx.ExecuteQuery() $ListItems.Count #Update Postion of the ListItemCollectionPosition $Query.ListItemCollectionPosition = $ListItems.ListItemCollectionPosition $Query.ListItemCollectionPosition If ($ListItems.Count -eq 0) { Break } #Update List Item ForEach($Item in $ListItems) { #Update List Item Title as File Name $testDocumentStatusColumn=$Item["ExampleColumnStatus"]

    If($testDocumentStatusColumn -ne "Closed") { $test=$Item; $file=$Item.File; #Get the List Item with all metadata fields of the File - here you can do further operation with file properties, if you need. #$ListItem = $File.ListItemAllFields $Ctx.Load($file) $Ctx.ExecuteQuery() $Item["ExampleColumnStatus"]="Closed" $Item.Update() $Ctx.ExecuteQuery() write-host "Item Updated!" -foregroundcolor Green } } Write-Host "=============================================================" Write-Host $count Write-Host "=============================================================" }While ($Query.ListItemCollectionPosition -ne $null)

    Server Side Code:

    $SPSite = "Site URL"
    $SPWeb = Get-SPWeb $SPSite
    $List = $SPWeb.Lists["TestDocumentLibray"]
    
    foreach($folder in $List.Folders)
    {
    $FName = $folder.name
    foreach($item in $folder.ListItems)
    {
    if($item["ExampleColumnStatus"] -ne "Closed")
    {
     $item["ExampleColumnStatus"]= "Closed"
     $item.Update() or $item.SystemUpdate()
    }
    }
    }
    $SPWeb.Dispose()

    PowereShell script References:

    Configure the PowerShell Script as a windows job in task scheduler:


    Thanks&Regards,

    Habibur Rahaman

    MCSA,MCP,MCTS

    My Certificates

    Note: If you feel the proposed answer is helpful, please mark as so or if this answered your question,please mark as answer.




    Saturday, October 26, 2019 10:06 AM
  • Hi Sowjanya,

    If the reply is helpful to you, you could mark the reply as answer. Thanks for your understanding.

    Best regards,

    Sara Fan

    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Monday, October 28, 2019 6:35 AM
    Moderator
  • Hi Habibur,

    It helped me .

    Those links are very helpful.

    still struggling with closing the document in co authoring in SharePoint online.

    Thank you,

    Sowjanya.

    Tuesday, October 29, 2019 5:37 PM