Skip to main content

Custom Activity

Custom Activity - the activity with custom edit form and custom visual display on canvas.

Creating custom activity

For creating a custom Activity, a class inherited from ActivityBase should be created. In the Parameters field of ActivityBase, two parameters, Name and State are stored; those are the name of the Activity and its state.

You can add variables of your own in the constructor. The variables are similar to the parameters in IDesignerParameterFormatProvider.

Parameters.Add(new CodeActionParameterDefinition()
{
Name = "Comment",
Type = ParameterType.TextArea
}
);

On entering this Activity, the Workflow Engine calls the ExecutionAsync method (PreExecutionAsync for PreExecution mode).

Example of a class:

using OptimaJet.Workflow.Core;
using OptimaJet.Workflow.Core.Model;
using OptimaJet.Workflow.Core.Runtime;

public class MyCustomActivity: ActivityBase
{
public MyCustomActivity() : base()
{
Type = "MyCustomActivity";
Title = "My Custom Activity";
Description = "The action is mine";

// the file name with your form template, without extension
Template = "MyFormTemplate";
// the file name with your svg template, without extension
SVGTemplate = "MySVGTemplate";

Parameters.Add(new CodeActionParameterDefinition()
{
Name = "MyField",
Type = ParameterType.TextArea
}
);
}

public override async Task ExecutionAsync(WorkflowRuntime runtime,
ProcessInstance processInstance, Dictionary<string, string> parameters,
CancellationToken token)
{
Console.WriteLine("MyCustomActivity:");
foreach(var item in parameters)
Console.WriteLine($"{item.Key} - {item.Value}");
Console.WriteLine("--------------");
}

public override async Task PreExecutionAsync(WorkflowRuntime runtime,
ProcessInstance processInstance, Dictionary<string, string> parameters,
CancellationToken token)
{

}
}

Custom form

To change the Activity form, you should create a new file with the .html extension in the templates folder, and specify its name in the Template field.

As an example, you can copy activity.html from the Designer

Custom canvas element

To change the Activity image in the canvas, you should create a new file with the .svg extension in the templates/elements folder, and specify its name in the SVGTemplate field.

As an example, you can copy activity.svg from the Designer

Registration

For registration, the WithCustomActivities method of the WorkflowRuntime should be executed:

_runtime.WithCustomActivities(new List<ActivityBase>() {new MyCustomActivity()});

Or you can register only one custom activity:

_runtime.WithCustomActivity(new MyCustomActivity());

All custom Activities will be displayed in the Elements panel:

1

To add your custom activity to the scheme, proceed as follows:

  1. Open the Elements panel.
  2. Find the activity in the list of elements or use Search.
  3. Drag the element to the canvas.