Overview
This is an article in a series of Sitecore how-to articles. These articles are meant to be quick guides to accomplish various tasks within Sitecore. The how-to articles have proven to be very helpful internally at One North Interactive https://www.onenorth.com. These articles assume working Sitecore knowledge. I just wanted to share the articles with the community. Hopefully you find them helpful.
How-To
Creating a custom workflow in Sitecore might be useful in a scenario where just publishing the item is not enough. In my case, I needed to publish a sub item, then publish its parent entity, and finally publish a related item on the initial sub item.
Step-by-step guide
- Create a new workflow item in the
- location /sitecore/system/Workflows/
- template /sitecore/templates/System/Workflow/Workflow
- Under that item, add two workflow states.
- template /sitecore/templates/System/Workflow/State
- Draft State, make sure the final check box is not selected.
- Publish State, make sure the final check box is selected. (This is the final workflow state)
- Using the workflow created in step 1, set an Initial state.
- The initial state should point to the Draft state created in step 2.1.
- Under the Draft state item created in step 2.2, add a Workflow command.
- template /sitecore/templates/System/Workflow/Command
- Set the Next state field to the Publish state created in step 2.3.
- Add the publish action to publish the initial item; this uses the publish action from the Sitecore kernel.
- the type should be “Sitecore.Workflows.Simple.PublishAction, Sitecore.Kernel”
- After the publish action, add a custom action; in my case it is titled Publish Parent Entity.
- Notice the Type string is set to a class contained in the website project.
- The code below gets the item being published, it then finds its parent item and publishes it.
using Sitecore.Data.Items; using Sitecore.Workflows.Simple; using Website.Logic.Common.Extensions; namespace Website.Logic.Common.Workflow { public class PublishParentEntityAction { public PublishParentEntityAction() { } public virtual void Process(WorkflowPipelineArgs args) { Item dataItem = args.DataItem; var parent = dataItem.Parent; if (parent != null) { PublishUtility.PublishItem(parent); } } } }