Getting active process tasks with a script

In this article we show how to obtain active business process tasks to automatically continue the process by a chosen route.

Script without PublicAPI.

Namespaces:
using EleWise.ELMA.Model.Services;
using EleWise.ELMA.Services;
using EleWise.ELMA.Tasks.Models;
using EleWise.ELMA.Workflow.BPMN.Diagrams.Elements;
using EleWise.ELMA.Workflow.Managers;
using EleWise.ELMA.Workflow.Models;
using EleWise.ELMA.Workflow.Services;

Script text:

// Create a task filter
var tasksFilter = InterfaceActivator.Create<IWorkflowTaskBaseFilter>();
tasksFilter.InstanceId = context.WorkflowInstance.Id; // Assign an ID for the process in which you want to identify the active tasks 
tasksFilter.DisableSecurity = true; // disabe checking access permissions for the tasks
tasksFilter.Statuses = TaskBaseExtensions.ActiveTaskStatuses.ToList(); // Select only active tasks
// Select tasks according to filter
var activeTasks = WorkflowTaskBaseManager.Instance.Find(tasksFilter, null);
foreach (var task in activeTasks)
{
    // Get the task's element on process diagram
    var element = (BPMNFlowElement)task.WorkflowBookmark.Instance.Process.Diagram.Elements.Single(e => e.Uid == task.WorkflowBookmark.ElementUid);
    // Find outgoing transition according to it's name
    var connector = element.OutputConnectors.FirstOrDefault(c => c.Name == "Transition 1");
    if (connector != null)
    {
        // The transition is found
        // Form data for task execution
        var executeData = new WorkflowTaskExecuteData(task, connector.Uid);
        // Execute task
        Locator.GetServiceNotNull<IWorkflowRuntimeService>().Execute(executeData);
    }
}
Creating a similar script with PublicAPI
Updated documentation on PublicAPI is available here.

Namespaces:

using EleWise.ELMA.API;
using EleWise.ELMA.Tasks.Models;
using EleWise.ELMA.Workflow.BPMN.Diagrams.Elements;
using EleWise.ELMA.Services;
using EleWise.ELMA.Workflow.Services;
using EleWise.ELMA.Workflow.Models;

Script task:

// Create task filter
var activeTasks = PublicAPI.Processes.WorkflowTaskBase.Filter()
                .InstanceId(context.WorkflowInstance.Id)
                .Statuses(TaskBaseExtensions.ActiveTaskStatuses.ToList()).Find();
foreach (var task in activeTasks)
{
    // Get task's element on process diagram
  var element = (BPMNFlowElement)task.WorkflowBookmark.Instance.Process.Diagram.Elements.Single(e => e.Uid == task.WorkflowBookmark.ElementUid);
  // Find outgoing sequence by it's name
  var connector = element.OutputConnectors.FirstOrDefault(c => c.Name == "Transition 1");
  if (connector != null)
  {
  // The transition is found
  // Form data for task execution
  var executeData = new WorkflowTaskExecuteData(task, connector.Uid);
  // Execute task
  Locator.GetServiceNotNull<IWorkflowRuntimeService>().Execute(executeData);
  }
}