Workflow in Sitecore ensures that items move through a predefined set of states before they are publishable, usually it’s to ensure that content is reviewed appropriately before publishing on the live website.
Important things to consider in workflow are
- States are building blocks of the workflow. It represents steps
- Commands allows users to transition content items from one
state to another.
- Actions automate functions in the workflow.
We will assign workflow to item template’s standard values so all the items that are published based on that template enters into the workflow which has to be followed.
In real scenario content item is created by one user it is then submitted and reviewed by another user, who will approve which will change the state to Approved then finally the publisher will approve and publish the item.
Editor creates item. Reviewer Approves item or Reject item.
If Item is rejected by reviewer then it will go back to Editor. If reviewer approves item it will then be in Approve and Publish state and can be approved and published by Publisher.
Create a workflow using /sitecore/System/Workflows/ and enter the name
Before assigning the initial state to this workflow, we first have to create the state.
2) Creating Workflow States
For that select workflow definition item and the select Insert from Template command and create the new workflow state using the /System/Workflow/State template.
Call the first state “Draft”.
Similarly create three more workflow states –Awaiting Approval, Approve and Publish,
It’s up to the requirement whether you have to create two levels or three of workflow. Here we will look at three levels of workflow where in as sitecore item reaches its final state i.e. Done then it will Auto Publish to Web Database.
At the end of this step you should have the following:
Now let’s set the Initial State as a Draft.
3) Creating Workflow Commands
To add command to a workflow
Create commands as shown in below diagram.
Now let’s set the transition from one state to another with the help of commands.
Click on Submit Command in Draft State and set the Next State to Awaiting Approval State.
Similarly select Approve in Awaiting Approval and set the Next State to Approve and Publish.
Select – Reject in Awaiting Approval State and set the Next State to Draft.
Similarly from Approve and Publish state Approve Command will point the Next state as Done and Reject Command will point the Next State to Awaiting Approval State.
4) Creating Workflow Actions
- Validation Actions
Select Approve Workflow Command, Right click and select Insert from TemplateCommand and create the new workflow action using /System/Workflow/Validation Action template. Call the new command “Validation Action”.
You will get the below screen. Enter the following information in Fields.
Type Field: Sitecore.Workflows.Simple.ValidatorsAction,Sitecore.Kernel.
Max Result Allowed: Warning
The maximum response from the validator.
The possible values are: Unknown,Valid,Suggestion,Warning,Error,CriticalError,FatalError
If the value of this field is “Error”, then items which have errors will pass, but the items which have critical errors will not pass.
Fill the error results with proper error messages that you want a user to see in case of validation errors.
Similarly add Validation Action at Approve in Approve and Publish State.
Auto Publish Action
The data section of this workflow action contains the following fields:
The namespace.class, assembly name of the implementation class.
For Example: Sitecore.Workflows.Simple.PublishAction, Sitecore.Kernel
The deep parameter that specifies whether or not the child items should be
— publish children
— do not publish children
— publish children (Sitecore 7.2 onwards)
5) Defining Workflow Final State
Select the state which is supposed to be the final state in workflow and select the Final Checkbox in the Data field:
Only those items which are approved by publisher in Approve and Publish state will move on to Done State of workflow and it will be published automatically.
6) Assigning workflow to a Template
It is always the best practice to assign the workflow to the standard values item of a template.
Select the Standard Fields Checkbox.
Leave the Workflow and the State field’s blank, as they will be filled automatically upon the item creation based on the workflow settings. Leave the Lock field as it is.
Save the template and now it is ready to use with workflow
Now let’s create roles and users and assign workflow states to appropriate roles.
7) Creating Roles
Its best practice to assign workflow rules to the roles and not to the users, so we will first create the roles and then assign it to users. We will create three roles.
Now as we have created roles we have to assign roles to a role for authoring a user with this particular role to login into sitecore and do some actions.
We will assign Sitecore Client Authoring to all the three roles.
Open Role Manager and follow the steps given in screenshot.
Similarly apply Sitecore Client Authoring to sitecoreReviewer and sitecorePublisher.
Additionally we need to assign Sitecore Client Publishing role to sitecorePublisher. sitecorePublisher should be able to publish items so this guy needs Sitecore Client Publishing role. sitecoreEditor and sitecoreReviewer won’t be able to publish any item of ProductPublishingWokflow workflow.
Now for each particular role we have to assign what items that particular user having these roles should be able to access or perform actions.
By default Read access is assigned to all the roles.
In my case MySearch is the root item and child items are in workflow. Child item’s template is MyItem template as shown in figure above to whom we have assigned the workflow in standard values items.
Similarly we assign Read, Write access to sitecoreReviewer role.
Publisher can approve/reject and publish the items, once publisher approves the item, it will be moved to Done state and it will be
automatically published. So similarly provide read/write access as in sitecoreReviewer role to sitecorePublisher role. We already have given an additional role to publisher for publishing the items so publisher can publish the items that are moved Done state incase if the item is in workflow.
Now the very important thing is we have to give proper access of workflow States to these three roles.
Let’s do step by step. First assign it to sitecoreEditor
now sitecoreEditor should only be able to create, edit and submit item to reviewer so we have to assign workflow states accordingly. sitecoreEditor should not be able to Approve or Publish Items. We have already assigned security settings to ProductsPublishingWorkflow and its Descendants. So Draft State is by default applied to the sitecoreEditor. Now we have to deny read access to Awaiting Approval, Approve and Publish and Done states from sitecoreEditor roles
Similarly sitecoreReviewer should not be able to create or submit item. It should only be able to approve or reject items.
sitecoreReviewer needs Awaiting Approval State access so we already have assigned it to Workflow and its descendants so it is by default applied to Awaiting Approval state. No need to assign or deny anything to Awaiting Approval state for sitecoreReviewer.
Remove Draft, Done, Approve and Publish states access from sitecoreReviewer as reviewer is not allowed to so.
And similarly for sitecorePublisher. Sitecore Publisher won’t be able to create item. It can only approve item for publish or reject item. So we have to deny read access for Awaiting Approval and Draft State.
8) Creating Users
Now we will create three users and assign these three roles respectively.
1) WebsiteEditor 2) WebsiteReviewer 3) WebsitePublisher
While creating user you will get an option to assign the roles to each user so assign the appropriate roles i.e. WebsiteEditor user will have sitecoreEditor role, WebsiteReviewer user will have sitecoreReviewer role and WebsitePublisher user will have sitecorePublisher role respectively.
That’s it. We are done.