Creating custom action workflow steps

Kentico enables you to write your own actions that you will be able to incorporate into a workflow process. The procedure consists of two steps - writing the code of the action and registering the action into the system.

Writing actions

  1. Create a new class and make it inherit from CMS.DocumentEngine.DocumentWorkflowAction.
  2. Override the Execute() method from the base class.
  3. Write the code that you want to be executed with the action into the Execute method's body.

Action steps can have parameters (settings) specified that you can use to modify their behavior. You can then enter the parameter's values when configuring an action step in the workflow designer.

If you want your custom action step to rely on parameters, you can specify them on the Actions of the Workflows application. To access the parameter's values in the code of an action, use the GetResolvedParameter method.

On this page

Kentico EMS required

Features described on this page require the Kentico EMS license.

 

To access the data of the page that will go through the action step, use the Node object and its properties.

If you are creating the class in the App_Code folder (or CMSApp_AppCode -> Old_App_Code if your project is a web application), add the RegisterCustomClass assembly attribute to register the class.

See Loading custom classes from App_Code for more information.

using System;
 
using CMS;
using CMS.DocumentEngine;
using CMS.Membership;
 
public class CustomAction : DocumentWorkflowAction
{
    public override void Execute()
    {
        // Gets the parameter value or assigns a default value - an empty string
        string appendText = GetResolvedParameter("MyParameter", "");
 
        // Appends the parameter value to the name of the page
        Node.DocumentName += appendText;
 
        // Saves the changes into the database
        TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);
        DocumentHelper.UpdateDocument(Node, tree);
 
    }
}

Registering actions in the system

  1. Open the Workflows application.
  2. Select the Actions tab.
  3. Click New action.
  4. Fill in the following mandatory fields:
    • Display name - name of the action step.
    • Action provider - Assembly name - name of the library that contains the action's code. Select (custom classes) for classes in App_Code.
    • Action provider - Class - full name of the class that contains the action's code.

  5. Click Save.
  6. (Optional) Define the action's parameters on the Parameters tab.

Was this page helpful?