I'm (trying to) using Reset-ItemField
to remove broken workflow links. While no error is shown in the console, the relevant fields are not changed.
$counter = 0
Get-Item -Path :master -Query "/sitecore/content//*[@__Workflow = '{f1fb8a76-9c0e-fcbb-3f7f-a57c84e92e39}']" |
ForEach-Object {
Write-Host "Workflow " $_["__Workflow"]
Write-Host "Workflow state " $_["__Workflow state"]
Write-Host "Default workflow " $_["__Default workflow"]
Reset-ItemField -Item $_ -Name @("__Workflow", "__Workflow state", "__Default workflow")
Write-Host "Workflow " $_["__Workflow"]
Write-Host "Workflow state " $_["__Workflow state"]
Write-Host "Default workflow " $_["__Default workflow"]
Write-Host "Broken workflow link found and removed from " + $_.Paths.FullPath
$counter++
if ($counter -gt 0) {
break
}
}
UPDATE 1
As Mark mentioned it is necessary to include the -IncludeStandardFields
parameter when modifying workflow via Reset-ItemField.
What I have found so far is that I can modify the default Sitecore homepage item (/sitecore/content/Home
) using with the following script:
$homeItem = Get-Item -Path :master -Query "/sitecore/content/Home"
Reset-ItemField -Item $homeItem -IncludeStandardFields -Name @("__Workflow", "__Workflow state", "__Default workflow")
This proves that SPE is not broken in this environment. It also implies that the issue here is either to do with the way I am retrieving items (using Get-Item with a query) or is to do with permissions on the items retrieved by my original query. It is strange, however, that there is no warning or error message when the cmdlet fails to update items. I have also tried wrapping the update foreach loop with a using block with a SecurityDisabler New-UsingBlock(New-Object -TypeName "Sitecore.SecurityModel.SecurityDisabler")
.
UPDATE 2
After attempting to manually clear the workflow fields, I realised that there is some item:saved
handler, or similar, which is re-assigning the workflow after the item is saved. This confirms that there is no problem with SPE or the script and there is no failure (or silent failure). I neglected to mention that the solution uses Sitecore Commerce Engine and I suspect there is some item:saved handler which is reassigning the workflow after an item is saved.