Sitefinity empowers you to extend the built-in workflow process by creating custom workflows. Using this approach you can fit the workflow to your organization's needs. The purpose of this article is to cover the process of creating custom workflows for built-in content types or custom content types derived from Sitefinity content. To extend the build in workflows you can get the default ones from the Sitefinity GitHub repository.
Custom wokflows are not supported for Standart Edition license - see license comparison
Sitefinity uses 4 different workflows for its built-in content types:
Depending on the content for which you want to extend the workflow process you must edit the necessary workflow file. For the purposes of this article we will extend the AnyContentApprovalWorkflow.xamlx file and apply it to NewsItem type.
Open your Sitefinity project in Visual Studio. You can either put the custom workflow file in Sitefinity project itself or build it in code library project and reference it in the Sitefinity project, here we will use the latter approach. Create a new code library project in your solution. Add the AnyContentApprovalWorkflow.xamlx file and set its Build Action to Embedded Resource.
In order to create a workflow activity we need to implement CodeActivity class or one of its derived classes. The activity we are going to create will check news items sent to be published, if their author field is not set the activity is going to populate it with the first and last names of the user sending the item for publish. All logic for this is added to the Execute method of the activity. This method accepts as a parameter the workflow context from which we can extract the item going through workflow and the user publishing it. Sample code bellow:
If the activities are part of the same project as the workflow file, they will be automatically added Visual Studio's toolbox for workflow activities. Open the workflow file for edit and go to ContentApproval. There you can see that the process branches depending on the active approval process for the particular content type. Choose the case in which you want to execute the custom code activity:
The workflow is now extended. The project can be build and its assembly added to the bin folder of the Sitefinity project.
You can register the custom workflows through the Sitefinity advanced settings. If the workflow is embedded in an assembly first you need to create a Virtual Path for it.
To create a Virtual Path go to Adminsitration -> Settings -> Advanced -> VirtualPathSettings -> Virtual paths and create a new Virtual Path. Configure the following properties:
The application relative path you want to use for the workflow.
The embedded resource path to the XAMLX file.
E.g. Telerik.Sitefinity.Samples.Workflow.Workflows.AnyContentApprovalWorkflow.xamlx, Telerik.Sitefinity.Samples.Workflow
Save the changes
To make a content type use a custom workflow you have to set this in the Workflow configuration editor. Go to Adminsitration -> Settings -> Advanced -> Workflow -> Workflows and find the type for which you want to use custom workflow, e.g. Telerik.Sitefinity.News.Model.NewsItem. Open this entry for edit and set the ServiceUrl property to the application relative path to the workflow file. If you have used an embedded file use the virtual path you have created for it, e.g. ~/SfSamples/AnyContentApprovalWorkflow.xamlx. Save changes and restart the website. If you have previously activated approval workflow for this item you need to deactivate it and activate a new one to use the custom workflow.
Back To Top