Skip to main content
Version: Next

Creating custom scheduled agents

Scheduled agents are background tasks that run cyclically or programmatically to perform automatic processing (synchronization, cleanup, notifications, etc.).

Basic principles

Any custom agent must inherit from the Avanteam.Application.Agents.AgentBase base class. This class provides the execution context and utility methods for interacting with the APS solution.

Agent structure

Here is the minimal structure of a custom agent:

using System;
using Avanteam.Application.Agents;

namespace MonExtension.Agents
{
public class MonAgentPerso : AgentBase
{
public MonAgentPerso(AgentContext agentContext, string context)
: base(agentContext, context)
{
}

protected override void Execute()
{
try
{
Log("Starting custom processing");

// Your logic here

Log("Processing completed successfully");
}
catch (Exception ex)
{
Log("Error during execution: " + ex.Message);
throw; // The exception will be caught by the agent engine
}
}
}
}

Data access

The AgentContext object passed to the constructor provides access to the platform's various data managers:

  • this.AgentContext.DocumentDataSource: Document and object management.
  • this.AgentContext.WorkflowDataSource: Process and instance management.
  • this.AgentContext.DirectoryDataSource: Directory and user management.
  • this.AgentContext.ApplicationDataSource: Unified global access.

Document reading example

var docMng = this.AgentContext.DocumentDataSource;
// Get a document by its ID
var doc = docMng.GetDocument("ID_DOCUMENT");

if (doc != null)
{
string titre = doc.GetStringValue("title");
// Processing...
}

Logging

Use the Log(string message) method inherited from AgentBase to write information to the agent logs. These logs are visible in the Process Studio agent administration interface.

Deployment

  1. Compile your .NET project targeting .NET Framework 4.8.
  2. Copy the generated DLL to the Bin directory of the APS application.
  3. In Process Studio, go to the Scheduled agents section.
  4. Create a new agent of type External (or custom).
  5. Enter the full class name (e.g.: MonExtension.Agents.MonAgentPerso, MonExtension.dll).
  6. Configure the execution frequency.