Skip to main content

Introducing Formengine - The New Formbuilder, try for FREE formengine.io.

Version: 6.1.0

Using Global Code Actions in Workflow Server

In this article we will describe briefly two easy methods of using Global Code Actions in Workflow Server.

Creating Code Actions in the visual scheme designer

Fist method consist in creating Code Actions in the visual scheme designer, it can be accessed in Workflow Server Admin GUI through 'Workflow' -> 'Manage schemes'. Once clicking on 'Code action' button in the toolbar, the code action window will appear. The Code Actions can be aggregated by taking in count the types: Action, Condition, RuleGet, RuleCheck. The code can be included in the JSON editor, and then it will be compiled. Afterward, the new Code Action will be available for the current scheme after saving the changes.

The list of namespaces in the 'Common Usings' field, can be edited also. The Code Actions are stored in the scheme, and then compiled after loading.

For instance, this example code can be added as follows:

var CustomParameter = new
{
CustomProperty = new
{
StringProperty = "New string is added"
},
IntProperty = 42
};

wfs code actions

After clicking on 'Compile', the compilation result will appear.

wfs code actions

Another example below:

string customParameter = processInstance.GetParameter<string>("CustomParameter");
if (customParameter is null) {
processInstance.SetParameter("CustomParameter", "42", ParameterPurpose.Persistence);
}
processInstance.IsParameterExisting("ParameterName");

wfs code actions

In case of creating an asynchronous Action (or Condition) in the scheme, the checkbox 'Async' must be enabled in the Code Actions window in the designer. Besides, if the attribute 'Is global' is set, Code Action will be saved in the WorkflowGlobalParameter table (or object), and it will be available in all schemes.

In addition, WorkflowRuntime must be configured in Program.cs in order to enable the creation of Actions in the visual scheme designer. The WorkflowRuntime should be notified about methods upon configuration if you are going to utilize them from your assemblies in your code (this line has been included already in the configuration example):

WorkflowRuntime.CodeActionsRegisterAssembly(typeof(System.Net.Http.HttpClient).Assembly);

Global Code Actions page in Workflow Server

A second option available in Workflow Server for using Code Actions, it can be accessed through 'Workflow' -> 'Global code actions'. In the Global code actions page, the same Code Actions can be created as in the visual scheme designer. The main difference is that they are available from all the schemes.

Below is an example that creates a simple method that processes a list of files:

void MyTask(string[] files)
{
foreach (string file in files)
{
// a time consuming operation with a file (compression, encryption, etc.)
Thread.Sleep(1000);
}
}

After saving the changes and clicking on 'Compile' button, the result comes into the notification window.

wfs code actions

Once a code action is added, it will become available in all schemes.

wfs code actions

tip

Additional information about customizing Actions, Parameters, Conditions and Activities can be read in Workflow Engine site.