Wednesday, November 4, 2015

Sitecore - Delete current version from an Item using Workflow Action

Current Environment: Sitecore 7.2 rev 140526

Requirement:
  • Need to remove the selected language from the item.
  • Need to remove it using the Sitecore Workflow Action 

Sitecore Step 1: Create a workflow action within the workflow which is set to that item template.

Create a workflow. (I used the default sample workflow).
You can find how to create the workflow action in sitecore cookbook: http://sdn.sitecore.net/upload/sitecore6/workflow_cookbook_a4.pdf

Sitecore Step 2: Provide Type String

Select the created workflow action.
In the Type String field provide the following details.
namespace.class_name, dll_name 

Do the following code for the class (.dll)

Coding:

     public class DeveleVersion
    {
        public void Process(WorkflowPipelineArgs args)
        {
            Item item = args.DataItem;
            
            Database db = Sitecore.Context.ContentDatabase;

            if (db == null || item == null) return;
            if (item.Versions.Count <= 0) return;
            using (new Sitecore.SecurityModel.SecurityDisabler())
            {
                item.Versions.RemoveVersion();
            }
            args.AbortPipeline();
        }
    }





2 comments: