Starting a process from a script
This article describes how to start a published process from a script. For the process to start, the initiator must have respective access permissions.
Attention
For correct functioning of the script, ELMA Designer must be installed on the PC with ELMA server.
Script with PublicAPI
Note
Documentation on PublicAPI is available here
Attention
The script below is relevant for ELMA 3.12.1 or lower.
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.String = "123"; //pecify value for String variable
};
var instance = PublicAPI.Processes.WorkflowInstance.StartProcess(startableProcess.Published, "Process instance name",
processContext);
}
Script without PublicAPI
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 == "Тest 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()).String = "123"; //specify value for a string variable
instance.Initiator = AuthenticationService.GetCurrentUser<IUser>();
var workflowService = Locator.GetServiceNotNull<IWorkflowRuntimeService>();
workflowService.Run(instance);
}
else
{
throw new Exception(SR.T("The process is not publshed")); // If the process is not published, display an error
}