The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.
If you still haven't got a chance to take a look at the part of our documentation about modifying existing Sitefinity workflow, may be this is the right moment. My colleague Radoslav Georgiev already showed you how to customize the Workflow notification messages. This blog post is about changing the AnyContentWorkflow.xaml in order to schedule an item for unpublishing right after you click on the Publish button. For this purpose you need to have Professional or Enterprise Sitefinity edition and the default workflow files. You can find the workflow files used by Sitefinity in the SDK (C:\Program Files (x86)\Telerik\Sitefinity 5.2\SDK\Content\Resources). Once you have the files, add them to a folder in your Sitefinity project - for example I'm adding them to my CustomWorkflows folder.Then navigate to Administration -> Settings -> Advanced -> Workflows and replace the the workflow you would like to customize as in the image.
Simply enter the relative path to your custom workflow file. Now you're ready to modify the AnyContentApproval.xaml file. Open it and click on Default workflow (we're going to modify the default workflow Sitefinity uses). After you do that you will see the Workflow diagram, where you will notice a Switch with all available actions that can be performed with an item. Follow the pointer to the Publish activity. The default Publishing operation ends with an ExecuteCodeActivity, where the draft version is checked in and Published. We're going to extend this behavior by adding a custom ExecuteCodeActivity class to the process.To do that add a class to your project, which inherits from Execute code activity and override the Execute protected method. In it do the following:
var dataContext = context.DataContext;
var masterFluent = dataContext.GetProperties()[
var masterFull = masterFluent.Get();
var temp = masterFluent.CheckOut();
var newsItemTempVersion = temp.Get();
newsItemTempVersion.ExpirationDate = System.DateTime.Now.AddMinutes(2);
In the above code we get the datacontext and from it - the draft item. Then we checkout to the temp version of the item and set an expiration date to it. The item is again checked in. This is all we need in our custom Execute activity. Now, to add it to your custom workflow simply go back to the AnyContentApprovalWorkflow.xamlx file and open the Visual Studio Toolbox. On top you will see your custom activity.
Drag and drop it on the workflow page and add a control flow, from the Publish activity to the custom one. This is all it takes to get your code working. There's one last thing we need to do to Unpublish the item. We add a ScheduleWorkflowCallActivity with Operation name Unpublish and we specify when this ScheduleWorkflowCallActivity should be executed. In our case, we want this to happen on the ExpirationDate of the item (which we set in the custom ExecuteCode activity), so we add the following code:
Now simply build the project and test the implementation. If you have followed all steps, each time you you publish a news item, you will also schedule it for unpublishing after particular time period. Now that you know how to customize Sitefinity workflows, the possibilies are countless. This is only one of the use-cases, but you can achieve many others. Hope you find this blog helpful.
View all posts from The Progress Team on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.
Subscribe to get all the news, info and tutorials you need to build better business apps and sites
Copyright © 2019 Progress Software Corporation and/or its subsidiaries or affiliates.
All Rights Reserved.
Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks for appropriate markings.