Workflow Management SPE Module
Sitecore PowerShell Extensions first encounter
Although I had heard of Sitecore PowerShell Extensions (SPE) several years ago I never used it myself until earlier this month. My interest was raised again during the Accelerated development with Sitecore PowerShell Extensions session by Adam Najmanowicz during SUGCON Europe 2016.
Right after I got back from SUGCON the project I was working on had a nice challenge. Workflows were being set on existing templates and hundreds of content items had already been created using these templates and had no workflow or workflow state set on them. We needed a way to update the content items with the workflow that was set on the Default workflow field on the updated templates.
For me this was an excellent opportunity to try SPE. I wrote a Sitecore PowerShell script to update Workflow and Workflow state fields, posted it in a gist and tweeted about it. I got in contact with Michael West and Adam Najmanowicz (the developers of SPE) who made some excellent suggestions to improve the user friendliness of the script.
Workflow Management Module
Adam asked if I could turn the script into a custom SPE module that could be installed alongside SPE. I really liked this idea and this made me delve deeper in SPE which is btw extremely well documented.
And now the Workflow Management module is ready. Currently only containing one toolbox action: Update workflow and state for content items but more will follow.
Installation
You'll need SPE v4 and Sitecore 8.x to make use of the module. The zip package can be found in the GitHub repo or on the Sitecore Marketplace (soon).
Install the zip package using the Installation Wizard:
Workflow Management toolbox
Once the package is installed you'll see that a Workflow Management element is added to the PowerShell toolbox:
When you click the Update workflow and state for content items action you'll be presented with the following dialog:
Here you need to select the workflow state which is expected to be set on the content items in a later stage.
Once you click Proceed the script will do the following:
- Find the workflow for the selected workflow state.
- Find the templates which have the workflow set on the Default workflow field in their __Standard Values.
- Find the content items based on these templates and only list those items which Workflow field are empty.
To update the content items with the workflow and workflow state you can choose between two actions in the menu:
- Update workflow for all items.
- Update workflow for selected items.
After running one of these actions you will see a notification about the number of items that have been processed. The list will be updated and now includes the workflow ID and workflow state ID values for the items.
Final Thoughts
This was mostly a fun learning exercise for me getting to know Sitecore PowerShell Extensions. I really like SPE and I plan to use it much more for automating tedious manual tasks.
I do hope this Workflow Management module can be of use to others. Please make sure you try it on a development or test environment first before using it on production.
When I tested it on 101 content items it took about 10 seconds to process them on my (outdated) local machine. So be careful when you want to process large amounts of items. In that case you might be better of with the simple script without the UI.
If you have any feature requests or issues, please post them on GitHub.