Santa

Let’s Talk

We would love to hear from you. Want to know more about
our services or have any questions? Say Hi!

How to update workflow using Powershell Script in Sitecore?

May 01, 2023
How to update workflow using Powershell Script in Sitecore?
Mitesh Patel
Mitesh Patel
Technical Head
how-to-update-workflow-using-powershell-script-in-sitecore

In this blog, we will understand how you can update the workflow using the Powershell Script in Sitecore.

When we create a new workflow and apply it to templates. Then this newly created workflow will apply to the newly created item only.

how-to-update-workflow-using-powershell-script-in-sitecore-1 how-to-update-workflow-using-powershell-script-in-sitecore-2

But the already existing item will not be affected. Because Sitecore never changes existing items by itself.

how-to-update-workflow-using-powershell-script-in-sitecore-3
Solution:

To apply the new workflow to existing items We can use the Powershell script.

how-to-update-workflow-using-powershell-script-in-sitecore-4

Script:

how-to-update-workflow-using-powershell-script-in-sitecore-5

In this script add the location after "$contentsToUpdate = Get-Item master: -Query" to apply workflow likewise in my case all items under the home will be updated to the new workflow.

In "$content.Fields["__Default workflow"].Value" and "$content.Fields["__Workflow"].Value" add your workflow Item Id.

In "$content.Fields["__Workflow state"].Value" add your workflow default status Id.

how-to-update-workflow-using-powershell-script-in-sitecore-6

When the Script runs successfully it returns the "True" value for each item and the workflow will apply to all items otherwise it returns the "False" value.

Conclusion

By following the above given process, you can successfully update the workflow in Sitecore using the Powershell Script.


YOU MAY ALSO LIKE