Pages

Tuesday, April 13, 2021

Unlock SharePoint NIntex Workflow Tasks With PowerShell

 

We had struggled with this task locking problem for a few months, once approver's completed task.  It seemed that the problem started after making updates from Microsoft and Nintex.  

It will display in the following message to edit workflow tasks

"This task is currently locked by a running workflow and cannot be edited."

After few hours research, I found out ways to unlock SharePoint Nintex workflow tasks using PowerShell script.


Solution:





[system.reflection.assembly]::LoadWithPartialName("Microsoft.SharePoint")

$siteUrl="http://TestSIte/"

$site=new-object Microsoft.SharePoint.SPSite($siteUrl)

$web=$site.OpenWeb()

$web.url

$i=0

write-host $web.lists

foreach($list in $web.lists){

    foreach($item in $list.items | where {$_[[Microsoft.SharePoint.SPBuiltInFieldId]::WorkFlowVersion] -ne 1}){

 

            if($item["Status"] -eq "Not Started")

            {

                  Try

                  {

                        Write-Host Unlocking workflow on $item.name

                        $item[[Microsoft.SharePoint.SPBuiltInFieldId]::WorkFlowVersion]=1;

                        $item.SystemUpdate()

                        $i++

                  }

                  Catch [System.Exception]

                  {

                        Write-Host Caught error trying to unlock workflow -ForegroundColor Red

                  }

            }

      }

}

Write-Host Unlocked $i workflows within $web.url

$web.dispose()

$site.dispose()

No comments:

Post a Comment