Workflow is tightly integrated into the Sitefinity CMS publishing process. Although you cannot see it in the user interface, even if you don’t define a workflow, Sitefinity CMS uses a default definition. This definition moves an item between several default states: draft, published, scheduled and unpublished. These default states are applied for items in all built-in content modules, unless you have defined another type of workflow. Although very similar, the default workflow should not be confused with content lifecycle.
Unlike the lifecycle, with workflow an item can be in only one state. When switching the workflow state, this actually changes the item, rather than creating a new row in the database. There are no new rows in the database, only new values in the existing rows for each item. Here is the meaning of default workflow states:
The diagram above shows how an item can move between the different states of the default workflow. Circles represent states, arrows represent actions that can be performed with content items. Those actions can be performed both from the Sitefinity CMS user interface, as well as the API.
A rule you can follow when dealing with lifecycle and workflow is that the workflow state of an item is always applied to the Master version in the lifecycle. This means that workflow does not have any meaning for Temp and Live versions.
To see how each action affects an item, we can observe the state of the database and the user interface of Sitefinity CMS, similar to how we did with the content lifecycle.
var manager = NewsManager.GetManager();
var newsItem1 = manager.CreateNewsItem();
"News Item 1"
Publishing the item creates a Live version in the lifecycle, and sets the workflow state of both Live and Master versions to Published.
When publishing the item through code, it's not enough to call the Publish method for the lifecycle - that would only create a live lifecycle version. To instruct the workflow that it should also change the state of the item to "Published", we need to call WorkflowManager.MessageWorkflow().
var item = manager.GetNewsItems().Where(n => n.Title ==
"News item 1"
&& n.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master).SingleOrDefault();
var temp = manager.Lifecycle.CheckOut(item)
item = manager.Lifecycle.CheckOut(item)
var bag =
WorkflowManager.MessageWorkflow(item.Id, typeof(NewsItem), null, "Publish", false, new Dictionary<string, string>());
This completes the sequence of steps through which we've moved a news item. Remember that while content lifecycle keeps several versions of an item, the default workflow operates on the master version by changing its status property. Knowing the difference between the two is important, and will become more evident when working with non-default workflow. We will discuss advanced workflow scenarios in the next topics of this section.
Back To Top