This article will cover how we can create a custom workflow action for Workflows with Sitecore.
Sitecore offers a few OOTB Submit Actions which can be used as per your requirements.
There are 2 steps in creating your custom workflow action:
The class will look like below:
using Sitecore.Diagnostics;
using Sitecore.Workflows.Simple;
using System;
using Sitecore.Data.Items;
namespace Foundation.Workflow.Actions
{
public class CustomWorkflowAction
{
public void Process(WorkflowPipelineArgs args)
{
try
{
Assert.ArgumentNotNull(args, "args");
Item dataItem = args.DataItem; // This will be the page item
ProcessorItem processorItem = args.ProcessorItem;
Item actionItem = processorItem?.InnerItem; // This will be the action item itself
string myValue = actionItem["My Field Name"]; // Access the values from the action like this
/*
Your code goes here
*/
}
catch (Exception ex)
{
Log.Error(ex.Message, this);
}
}
}
}
Now, you can add the action item under the workflow command on which you need it to be triggered. Remember to add the value for the Type field as the fully qualified name of the class.
Happy Sitecoring!