Sitecore Workflow Auto Publish Media Items
Posted by Bhavik Patel on 7/3/2015
When you install a default Sitecore 7 instance, you will notice that there is a “Sample Workflow” already configured for you. The final step of this workflow has an “Auto Publish” action, which automatically publishes an item once it reaches the final step of workflow. How handy! If you take a look at the action, you’ll notice that Sitecore has some code to execute that action.
For a project that I was recently working on, we decided we would leverage this code, as we wanted to perform an auto-publish of items when they were finally approved. We created our workflow and for in the final step, added an “Auto Publish” action with the same settings Sitecore provided in their sample workflow shown above.
After some testing, we noticed it worked quite well, publishing items as they were approved in our workflow. However, we quickly noticed that if we had image fields in our content items and uploaded new images, those images did not get published along with the item. That prompted me to look into the “Parameters” field of the “Auto Publish” action. As you may have noticed, there is a “deep” parameter specified for the action. Disassembling the code, I found that this parameter is used by the code to perform publishing of sub-items along with the item. Further analysis of the code led me to another parameter, namely “related”. This is used by the code to perform a publishing of related items along with the item. That was the ticket.
So, in summary, to auto-publish newly uploaded media items along with your content items in workflow, using Sitecore’s “Auto Publish” action, make sure you provide the “related=1” parameter. Note that this option is only available in Sitecore 7 onwards, as the “Publish Related Items” option was not available in earlier versions of Sitecore.