Finding active document approval processes with a script
A script for finding active document approval processes. You need to add an exclusive gateway and a script activity at the beginning of a script.
Make the "There are active processes" the default transition.
Context variables:
Document (context.DocumentHere) – variable of the Document type. The document which is sent for approval.
Iterator (context.Iterator) – variable of the Integer type (cannot be empty; the default value is 0)
Process List (context.CheckList) – variable of the Text type.
Add namespaces:
using EleWise.ELMA.Model.Services;
using EleWise.ELMA.Workflow.Models;
using EleWise.ELMA.Workflow.Managers;
The script in the Find Active Processes activity:
var filter = InterfaceActivator.Create<IWorkflowInstanceFilter>(); //Create a filter of process instances
filter.GeneralStatus = WorkflowInstanceGeneralStatus.Current; //Find active processes
filter.Query = String.Format("Id IN (FROM P_Approvement SELECT WorkflowInstance WHERE DocumentThere = {0})", context.DocumentHere.Id.ToString());
var findedWorkflows = WorkflowInstanceManager.Instance.Find(filter, null); //Find process instances by the specified filter
//Write the names of the active approval processes to the CheckList variable
foreach(var proc in findedWorkflows)
{
context.CheckList += "\n" + proc.Name.ToString(); //Write the names of the process instances
context.Iterator++; //Add to the counter of active processes
}
About filter.Query:
P_Approvement - database class name of the process, whose instances are searched. You can find this name on the Settings tab of the business process.
DocumentThere - the name of the context variable in the database. Matches with this variable are searched. In this example, you need to find a document. The name is displayed on the Context tab of the business process.
In the condition of the No active processes specify this script:
if(context.Iterator == 0)
return true;
else
return false;