Action Library
Introduction
The Action Library allows you to extend Process Studio functionalities by creating reusable actions that you can call in your workflows.
There are two types of actions in Process Studio:
- Simple transition actions: No-code configuration to modify fields when passing through a transition.
- Custom Action Library: Advanced actions in C#, JavaScript or DLL called from Script Tasks.
1. Simple Transition Actions
Description
Simple actions allow you to automatically modify form fields when passing through a transition, without writing code.
Typical usage: Update a status, automatically fill a date, copy a value.
Access
- Right-click on a transition (arrow between two steps).
- Select Actions from the context menu.
Configuration
Interface: A list of actions to execute sequentially.
| Column | Description | Example |
|---|---|---|
| Field | Select the form field to modify. | "Status", "Validation_Date", "Total_Amount". |
| Value | Enter the value to assign. | "Validated", "2024-01-15", "1000". |
| Expression | (Advanced mode) Use a C# expression to calculate the value. | DateTime.Now, instance.GetFieldValue("Price") * 1.2 |
Buttons:
- Add: Creates a new action.
- Remove: Removes an action from the list.
- Move Up/Down: Reorganizes the execution order.
Usage Examples
Example 1: Update a status
Context: Transition "Validation → End".
Action:
- Field:
Status - Value:
Closed
Result: When the document passes through this transition, the "Status" field is automatically set to "Closed".
Example 2: Automatically fill a date
Context: Transition "Manager Validation → HR Validation".
Action:
- Field:
Manager_Validation_Date - Expression:
DateTime.Now
Result: The validation date is automatically filled with today's date.
Example 3: Calculate tax-inclusive amount
Context: Transition "Input → Verification".
Action:
- Field:
Tax_Inclusive_Amount - Expression:
instance.GetFieldDoubleValue("Tax_Exclusive_Amount") * 1.2
Result: The tax-inclusive amount is automatically calculated (tax-exclusive × 1.2).
Advanced Mode (Expressions)
You can use C# expressions to dynamically calculate the value.
Available objects:
instance: Access to the current document (fields, metadata).DateTime: Date manipulation.Math: Mathematical functions.
Common methods:
| Method | Description | Example |
|---|---|---|
instance.GetFieldValue("Name") | Retrieves a field value (string). | instance.GetFieldValue("Requester") |
instance.GetFieldDoubleValue("Amount") | Retrieves a numeric field (double). | instance.GetFieldDoubleValue("Price") |
instance.GetFieldDateTimeValue("Date") | Retrieves a date field (DateTime). | instance.GetFieldDateTimeValue("Due_Date") |
DateTime.Now | Current date and time. | DateTime.Now |
DateTime.Now.AddDays(7) | Current date + 7 days. | DateTime.Now.AddDays(7) |
[!TIP] Prefer simple transition actions for common operations. It's more readable and maintainable than a script in a Script Task.
2. Custom Action Library
Description
The Action Library is an advanced feature allowing you to create reusable actions in C#, JavaScript or via external DLLs.
These actions are then called from Script Tasks to execute complex operations.
[!WARNING] This feature is intended for technical profiles (developers, system administrators). It requires knowledge of C# or JavaScript programming.
Accessing the Library
- In the Process Studio navigator, select Workflows → Action library.
- A panel displays on the right with the list of available actions:
- Standard actions: Provided by default with Process Studio.
- Custom actions: Created by administrators.
Creating a Custom Action
Step 1: Create a new action
- In the Action library, click New.
- The creation dialog appears:

Step 2: Configure the action
| Parameter | Description | Example |
|---|---|---|
| Category | Classifies the action in a folder (organization). | "Business Calculations", "ERP Integrations", "Email Sending". |
| Name | Technical name of the action (unique identifier). | "CalculateClientDiscount", "SynchronizeERP", "SendInvoicePDF". |
| Description | Explanation of the action's role (documentation). | "Calculates client discount based on annual revenue". |
| Type | Type of code used to implement the action. | C# Code, Javascript Code, Expected code library. |
Available types:
| Type | Description | Usage |
|---|---|---|
| C# Code | Write C# code directly in the editor. | Complex business logic, API calls, advanced calculations. |
| Javascript Code | Write JavaScript code (executed client-side). | Client-side validation, DOM manipulation. |
| Expected code library | References an external DLL (.NET assembly). | Reuse existing code, integration with third-party systems. |
Step 3: Write the action code
Code editor: A C# editor with syntax highlighting and line numbering is available.
Code structure:
using System;
using System.Collections.Generic;
using Avanteam.Documents;
using Avanteam.Kernel;
using Avanteam.Workflow.Runtime;
namespace Avanteam.Workflow.ComponentModel.Actions
{
public class MyAction
{
public bool Execute(Hashtable parameters)
{
// Retrieve parameters
var dataSource = parameters["ApplicationDataSource"] as DataSource;
var instance = parameters["EngineInstance"] as Instance;
// Access document fields
var taxExclusiveAmount = instance.GetFieldDoubleValue("Tax_Exclusive_Amount");
// Perform a calculation
var taxInclusiveAmount = taxExclusiveAmount * 1.2;
// Modify a field
instance.SetFieldDoubleValue("Tax_Inclusive_Amount", taxInclusiveAmount);
// Return true if success, false if error
return true;
}
}
}
Available objects in parameters:
| Key | Type | Description |
|---|---|---|
ApplicationDataSource | ApplicationDataSource | Access to Process Studio database, current document and SQL query functions. |
Instance | Instance | The current workflow instance being executed (hierarchical navigation, invocation, status). |
TrackerInformation | object | Workflow tracking information. |
Useful methods on ApplicationDataSource:
| Method | Description | Example |
|---|---|---|
dataSource.Document.GetStringValue("Field") | Retrieves the value of a text field. | dataSource.Document.GetStringValue("Requester") |
dataSource.Document.GetStringList("Field") | Retrieves a list of values (multi-valued field). | dataSource.Document.GetStringList("Collaborators") |
dataSource.Document.IdDocument | Retrieves the unique ID of the document. | dataSource.Document.IdDocument |
dataSource.DocumentsDataSource.SQL_ExecuteScalar(sql, params) | Executes a SQL query and returns a single value. | dataSource.DocumentsDataSource.SQL_ExecuteScalar("SELECT COUNT(*) FROM Documents", ...) |
dataSource.DocumentsDataSource.SQL_ExecuteNonQuery(sql, params) | Executes an SQL insert/update query. | dataSource.DocumentsDataSource.SQL_ExecuteNonQuery("INSERT INTO ...", ...) |
dataSource.DocumentsDataSource.SQL_ExecuteScalarCollection<T>(sql, params) | Executes a SQL query and returns a collection of results. | dataSource.DocumentsDataSource.SQL_ExecuteScalarCollection<string>("SELECT dn_name FROM ...", ...) |
dataSource.UserName = "Automatic" | Changes the current user (for system actions). | dataSource.UserName = "Automatic"; |
Useful methods on Instance:
| Method | Description | Example |
|---|---|---|
instance.Runtime.InvokeInstance(instance) | Triggers/Invokes a specific workflow instance. | instance.Runtime.InvokeInstance(instWI); |
instance.NavigateRootParent | Navigates to the workflow root instance. | instance.NavigateRootParent |
instance.Childs | List of child instances. | foreach (Instance child in instance.Childs) |
instance.Nexts | List of next instances. | foreach (Instance next in instance.Nexts) |
instance.Status | Instance status (Complete, Running, etc.). | if (instance.Status == InstanceStatus.Running) |
instance.Component.ComponentType | Component type (Activity, Workitem, etc.). | instance.Component.ComponentType.ToString() == "Workitem" |
instance.Component.Id | Component identifier. | instance.Component.Id == "Validated" |
[!NOTE] To execute SQL queries, always use parameters (
new KeyPair("name", value)) to avoid SQL injections.
Step 4: Validate and save
- Click Validate to compile the code.
- If errors are detected, they display in the console.
- Correct the errors and validate again.
- Click OK to save the action.
Using an Action in a Workflow
Once the action is created, you can call it from a Script Task.
Step 1: Add a Script Task
- In the workflow designer, add a Script Task (rectangle with gear).
- Double-click on the task to open its properties.
Step 2: Select the action
- In the Script tab, click Select an action.
- The list of available actions appears (categories + actions).
- Select your action (ex: "Business Calculations → CalculateClientDiscount").
- The action is added to the task.
Step 3: Configure parameters (optional)
Some actions require parameters. You can configure them in the script task properties window.
Custom Action Examples
Example 1: Calculate client discount
Category: Business Calculations
Name: CalculateClientDiscount
Type: C# Code
Code:
using System;
using System.Collections;
using Avanteam.Application;
using Avanteam.Application.DataSource;
using Avanteam.Workflow.Runtime;
namespace Avanteam.Kernel.Scripting
{
public class CSCode
{
public bool Execute(Hashtable parameters)
{
ApplicationDataSource dataSource = parameters["ApplicationDataSource"] as ApplicationDataSource;
Instance instance = parameters["Instance"] as Instance;
// Retrieve client's annual revenue (form field)
string annualRevenueStr = dataSource.Document.GetStringValue("Client_Revenue");
double annualRevenue = string.IsNullOrEmpty(annualRevenueStr) ? 0 : double.Parse(annualRevenueStr);
// Calculate discount based on revenue
double discountRate = 0;
if (annualRevenue > 100000)
discountRate = 15; // 15% if revenue > 100k€
else if (annualRevenue > 50000)
discountRate = 10; // 10% if revenue > 50k€
else
discountRate = 5; // 5% otherwise
// Save discount rate in document
dataSource.DocumentsDataSource.SQL_ExecuteNonQuery(
"UPDATE Documents SET Discount_Rate = @rate WHERE id = @id",
new KeyPair("rate", discountRate.ToString()),
new KeyPair("id", dataSource.Document.IdDocument)
);
return true;
}
}
}
Example 2: Verify closure of all sub-documents
Category: Workflow Management
Name: VerifySubDocumentsClosure
Type: C# Code
Code:
using System;
using System.Collections;
using Avanteam.Application;
using Avanteam.Application.DataSource;
using Avanteam.Workflow.Runtime;
using Avanteam.Kernel;
namespace Avanteam.Kernel.Scripting
{
public class CSCode
{
public bool Execute(Hashtable parameters)
{
ApplicationDataSource dataSource = parameters["ApplicationDataSource"] as ApplicationDataSource;
Instance instance = parameters["Instance"] as Instance;
// Count unclosed sub-documents
string sql = @"SELECT COUNT(*)
FROM DocumentProcess DP
INNER JOIN Documents D ON DP.id_document = D.id
WHERE D.Parent_Id = @idParent
AND DP.process_status != 2"; // 2 = Closed
object oNbSubDoc = dataSource.DocumentsDataSource.SQL_ExecuteScalar(
sql,
new KeyPair("idParent", dataSource.Document.IdDocument)
);
// If all sub-documents are closed, continue
if (oNbSubDoc != null && oNbSubDoc.ToString() == "0")
{
// All sub-documents are completed
// You can trigger workflow continuation here
return true;
}
else
{
// Some sub-documents are still in progress
// Do not continue
return false;
}
}
}
}
Best Practices
1. Simple Actions vs Custom Actions
| Criteria | Simple actions (Transition) | Custom actions (Library) |
|---|---|---|
| Complexity | Simple operations (assign a value). | Complex logic (calculations, external calls). |
| User profile | Functional administrator. | Developer / Technical profile. |
| Reusability | Specific to one transition. | Reusable in multiple workflows. |
| Visibility | Less visible (hidden in transition). | Very visible (Script Task in diagram). |
| Maintenance | Easy (no-code). | Requires technical skills. |
Recommendation:
- ✅ Use simple actions for 80% of cases (statuses, dates, field copies).
- ✅ Create custom actions for specific business logic or integrations.
2. Library Organization
- Categorize your actions: Use clear categories ("Calculations", "Integrations", "Notifications", "Document Management").
- Name explicitly: "CalculateDiscountRate" rather than "Action1".
- Document: Always fill the "Description" field.
3. Performance
- Limit network calls (APIs, external databases).
- Optimize SQL queries if you query the Process Studio database.
4. Security
- Validate inputs (form fields) before using them.
- Don't expose sensitive data in logs.
- Limit action rights (database access, file system).
See also:
- Workflow Activities - Script Task configuration
- Transitions & Logic - Transition configuration
- Workflow Verification - Detecting compilation errors