Starting a process from a script

This article describes how to start a published process from a script. For the process to start, the user who initiates the start must have respective access permissions. 

For correct functioning of the script, ELMA Designer must be installed on the PC with ELMA server.

Script text:

using EleWise.ELMA.Security.Models;
using EleWise.ELMA.Security.Services;
using EleWise.ELMA.Services;
using EleWise.ELMA.Workflow.Managers;
using EleWise.ELMA.Workflow.Services;
using EleWise.ELMA.Extensions;
var startableProcess = ProcessHeaderManager.Instance.GetStartableProcesses().FirstOrDefault(a=>a.Name == "ТTest process" && a.Published != null);
if (startableProcess != null)
    var process = startableProcess.Published;
    var instance = WorkflowInstanceManager.Instance.Create();
    instance.Process = process;
    instance.Name = "Process instance name"; //process instance name
    (instance.Context.AsDynamic()).Stroka = "123"; //specify value for a string variable
    instance.Initiator = AuthenticationService.GetCurrentUser<IUser>();
    var workflowService = Locator.GetServiceNotNull<IWorkflowRuntimeService>();
    throw new Exception(SR.T("The process is not publshed")); // If the process is not published, display an error


Creating a similar script with PublicAPI
Updated documentation in PublicAPI is available here.

Script text:

var startableProcess =
    PublicAPI.Processes.ProcessHeader.Find("Name like ’Test process’").FirstOrDefault(a => a.Published != null);
if (startableProcess != null)
    Action<dynamic> processContext = myContext => //specify value for String variable
       myContext.Stroka = "123"; //pecify value for String variable
    var instance = PublicAPI.Processes.WorkflowInstance.StartProcess(startableProcess.Published, "Process instance name",