allBlogsList

Preview an item in workflow

Sitecore gives us an option of previewing an item before publishing it to the web database using the Preview Mode. Recently, we noticed that the preview mode doesn’t work for items until they are in the Final State of workflow. This article outlines how we configured the sites in order to address this issue.

Preview_Mode

Since the client wanted to use workflow, they have added the parameter enableWorkflow=true for every new site they have created. The way workflow was set for the client, it was defined in multiple states.

  • Draft: This is the initial state of workflow where the author(s) add or update an item and then submit it to the next state.
  • Review: During this state, the users in the roles of Content Reviewers review the changes made to an item using the Preview Mode and approve if everything looks appropriate.
  • Approval: This is the final state of workflow where the Content Approvers make a decision to approve or reject the content based on business requirements. Once approved, it is auto published to the web database including related items.

We noticed that the Preview mode is not working for the items until they are in final state of workflow. This makes it difficult for the content reviewers to approve the content without having the ability to preview the page.

After decompiling the Sitecore assemblies, I realized that enableworkflow=true is only required for sites which are running on Live Mode. With Live Mode configuration, a Sitecore website runs off of full content database, known as the master database, as opposed to the published content database, known as the web database.

We updated all the site definitions attribute by setting enableWorkflow=false. I realized even with this flag turned off, the workflow and Preview Mode was working as expected.

How is Workflow still working?

When we are using the Content Editor, the SiteContext is set to Shell, so it looks for the attribute in the shell site definition, which by default has that flag set to true.

site_shell

When we are using the Experience Editor, the SiteContext is set to respective site yet it still works because the trick lies in the Sitecore.Sites.SiteContext.SetDisplayMode() method located in the Sitecore.Kernel.dll.

    /// 

If you take a look at code snippet above under Line 17, irrespective of the site we are on, enableWorkflow is always set to the value defined under shell site definition.