Sitecore workflows – Comment if you reject something!


sitecore workflows - reject comment required

One of our clients recently asked us to update the Sitecore publishing workflow so that authors could not block publishing without adding a comment explaining why the article is not fit for publishing. Fortunately, Sitecore allows you to plug in additional actions for every workflow command. The idea was to create an action which will check whether the workflow approver entered the reason for rejection and abort the workflow state change if the message is empty.

The solution we put in place is as follows:

1 – Create a new class RejectCommentValidationAction with a code:

namespace Cognifide.SiteCore.Web.Logic.Workflow
{
    public class RejectCommentValidationAction
    {
        public void Process(Sitecore.Workflows.Simple.WorkflowPipelineArgs args)
        {
            if (string.IsNullOrEmpty(args.Comments))
            {
                Sitecore.Web.UI.Sheer.SheerResponse.
                    Alert("You cannot reject without comment", string.Empty);
                args.AbortPipeline();
            }
        }
    }
}

2 – Create a new Validation Action item below the Reject command and set its Type field to Cognifide.SiteCore.Web.Logic.Workflow.RejectCommentValidationAction, Cognifide.SiteCore.Web. And that’s it.


sitecore workflows - mandatory comment for reject command

If the rejection message is not entered, a sheer dialog will popup with information about missing comment.

Note: You may easily extend the action code to use the messages which are set in the fields of the action item in Sitecore using args.ProcessorItem.InnerItem["Error"].

If you found this post interesting, then do check out my other Sitecore posts.

  • Łukasz Morawski

    Very nice article.