Why Wait for Document to be Unlocked by Document Editor Sucks

If you are using the SharePoint Designer action wait for document to be unlocked by document editor, you may be aware of it’s shortcomings.  Like what?  Well, if you submit a form or document to the library, this action fires.  If the form/document happens to be a little slow getting to the library, the workflow will pause for another 5 minutes!  ¡No bueno! 

What I did to get around this was, write a little inline PowerShell script as my first action in the Workflow.  The script loops every 5 seconds to see if the form/document has been unlocked.  5 seconds vs 5 minutes, there is a large difference.

How? If you don’t already have the iLove SharePoint Workflow Actions installed, do it! The actions can be downloaded here: http://ilovesharepoint.codeplex.com/ .  (read the documentation)

Once installed, modify your Worflow or create a new one. I replaced the lame Wait for Document to be Unlocked by Document Editor with a Execute PowerShell action. The PowerShell code is below.


if(-not(Get-PSSnapin | where { $_.Name -eq "Microsoft.SharePoint.PowerShell"}))
{
 Add-PSSnapin Microsoft.SharePoint.PowerShell;
}

$site = Get-SPweb "http://sharepointed.com/sites/taco/"
$mList=$site.Lists["The Library"]
$item = $mList.GetItemById([<strong><span style="text-decoration: underline;">%Current Item:ID%</span></strong>])

$Lock = $item.File.LockType

while($Lock -ne "None")
 {
 start-sleep -s 5
 $Lock = $item.File.LockType
 }

Please notice the line $item = $mList.GetItemById([%Current Item:ID%]), Current Item: ID is the ID of the item that started the workflow.  This is key to Workflow action working!

*update*

It’s also a good idea to modify your default view and other views to only show workflow items that have a completed status.  How?  Edit the view, scroll down to the Filter section, select the column that has your workflows name in it.  The next drop down should be ‘is equal to‘ and the text box, input the number five 5.  5 represents the Completed workflow status.

SharePoint Completed Workflow Status

SharePoint Completed Workflow Status

Leave a Reply

Your email address will not be published.