Home Gitesh Portfolio Blog About Me Gallery Contact

Sitecore: Worklfow State Update

With this powershell command you will be to update the workflow state of an item in Sitecore content tree.

In the below code we are updating the content items with the workflow of media content.

 

Write-Host ----  Execution Start  ----
$mediaContentWorkflow = "{D30C6410-C5B1-4EC4-80AE-88A112129FFB}"
$mediaContentWorkflowApproved = "{5B53F05D-EFC9-4086-81A2-273E33B48990}"
$mediaContentWorkflowAwaitingApproval = "{2A9CF946-C687-4352-B25C-4029BB6D903D}"
$mediaContentWorkflowDraft = "{7F2E47AA-C324-4217-A0AD-3121AA1CB6A0}"
$mediaContentWorkflowPublished = "{5A79820C-8CEE-42F3-9216-6B6793C1656A}"

$contentWorkflow = "{077B84FE-ABB5-4D96-A9B8-D6AEE99261D2}"
$contentWorkflowApproved = "{12C0A4DF-E66E-4852-BBFB-7810880F1A6F}"
$contentWorkflowAwaitingApproval = "{23438625-3CEC-45FA-81FE-CBCAB7E8EAB4}"
$contentWorkflowDeletionApproval = "{B792999D-23B1-46F7-8D39-A2F3873E9B6B}"
$contentWorkflowDeletionApproved = "{80430AD1-C551-497D-A18B-516669A606DF}"
$contentWorkflowDraft = "{B0273CA9-F122-4D6E-A87F-9B52B20771AE}"
$contentWorkflowPublished = "{3530AF77-5F64-4A81-83A6-9C21F36A5187}"

$sourcePath = "/sitecore/content/ProjectName/Home/Home/media-releases"
$children = Get-ChildItem -Path "master:${sourcePath}" -Recurse -Language * -Version * | Where-Object { $_.TemplateName -match "^Media Article$" }
foreach ($child in $children) {
	Write-Host ----  Processing item : $child.Paths.FullPath Version: $child.Version ----
	if ($child.__Workflow -eq $contentWorkflow) {
		Write-Host Updating workflow $child.__Workflow to $mediaContentWorkflow
		$child.Editing.BeginEdit()
		$child.__Workflow = $mediaContentWorkflow
		$child.Editing.EndEdit()
	}
		
	if ($child."__Workflow state" -eq $contentWorkflowApproved -or $child."__Workflow state" -eq $contentWorkflowDeletionApproved) {
		Write-Host Updating workflow state $child."__Workflow state" to $mediaContentWorkflowApproved
		$child.Editing.BeginEdit()
		$child."__Workflow state" = $mediaContentWorkflowApproved
		$child.Editing.EndEdit()
	}
	elseif ($child."__Workflow state" -eq $contentWorkflowAwaitingApproval -or $child."__Workflow state" -eq $contentWorkflowDeletionApproval) {
		Write-Host Updating workflow state $child."__Workflow state" to $mediaContentWorkflowAwaitingApproval
		$child.Editing.BeginEdit()
		$child."__Workflow state" = $mediaContentWorkflowAwaitingApproval
		$child.Editing.EndEdit()
	}
	elseif ($child."__Workflow state" -eq $contentWorkflowDraft) {
		Write-Host Updating workflow state $child."__Workflow state" to $mediaContentWorkflowDraft
		$child.Editing.BeginEdit()
		$child."__Workflow state" = $mediaContentWorkflowDraft
		$child.Editing.EndEdit()
	}
	elseif ($child."__Workflow state" -eq $contentWorkflowPublished) {
		Write-Host Updating workflow state $child."__Workflow state" to $mediaContentWorkflowPublished
		$child.Editing.BeginEdit()
		$child."__Workflow state" = $mediaContentWorkflowPublished
		$child.Editing.EndEdit()
	}
	Write-Host ----  Finished processing item  ----
}
Write-Host ----  Execution Finished  ----

Posted: 13/07/2022 5:36:20 p.m. by Gitesh Shah | with 0 comments