Skip to main content
Version: Next

Advanced Actor Scripting

Introduction

For complex workflow needs where standard actors (Manager, Group, Form Field) are not sufficient, Process Studio offers the ability to define Script Actors. This feature allows you to use C# code to dynamically determine the list of users who should receive a task.

Typical Use Cases

  • Assign a task to a validator whose name is calculated by an external business rule (Web Service, third-party database).
  • Determine the validator based on a complex amount threshold and budget structure.
  • Distribute workload (Round-robin) among team members.

The Actor Editor

When creating an Actor (Resources > New actor menu), choose the C# Script type.

The interface presents a code editor with syntax highlighting and compilation verification.

Script editor for actor

Code Structure

The script must implement a class (named CSCode by default) with an Execute method that returns a collection of strings (ICollection<string>). These strings correspond to the Logins or DN (Distinguished Names) of the targeted users/groups.

Default Template

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Avanteam.Application.DataSource;
using Avanteam.Application.Security;
using Avanteam.Workflow.ComponentModel;
using Avanteam.Workflow.Runtime;

namespace Avanteam.Kernel.Scripting
{
public class CSCode
{
public ICollection<string> Execute(Hashtable parameters)
{
// Get context
var dataSource = parameters["ApplicationDataSource"] as ApplicationDataSource;
var instance = parameters["Instance"] as Instance;

var ret = new List<String>();

// TODO - Add your logic here

return ret;
}
}
}

Available Parameters

The Execute method receives a Hashtable parameters containing:

  • ApplicationDataSource: Access to application data (database, SQL queries).
  • Instance: The workflow instance currently executing. Provides access to form fields via instance.XmlFields.

Concrete Example

Scenario: We want to assign validation to a project manager, whose identifier is stored in a txt_resp_projet form field, but only if the amount exceeds €1000. Otherwise, the standard manager validates.

public ICollection<string> Execute(Hashtable parameters)
{
var instance = parameters["Instance"] as Instance;
var ret = new List<string>();

// Read form fields
string responsableProjet = instance.XmlFields.GetElementValue("txt_resp_projet");
string montantStr = instance.XmlFields.GetElementValue("txt_montant");
double montant = 0;
Double.TryParse(montantStr, out montant);

if (montant > 1000 && !string.IsNullOrEmpty(responsableProjet))
{
// Dynamic assignment to project manager
ret.Add(responsableProjet);
}
else
{
// Return empty string or null to let workflow use default mechanism
// OR we can explicitly return the initiator's manager if we want to force the rule here
// ret.Add(instance.Creator.Manager);
}

return ret;
}

Best Practices

  • Performance: Avoid heavy SQL queries or slow synchronous Web Service calls in the actor script, as this can slow down task creation.
  • Error Handling: Wrap your critical code in try/catch blocks to avoid blocking the workflow if data is missing.
  • Testing: Use the Check button to validate C# syntax before saving.