Sub-Process Initiation
Through one process, a different process can be initiated. This function will help meet many different needs. Here, rather than triggering a different process, we are talking about the situation where one process is a sub-process of another process.
There can be one main process and more than one sub-process. The project of the sub-processes may not be under the same solution as the main process.
Sample flow design for main process
Sub-process initializations will be performed on the function object.
Sub-process operations are carried out using eBAPI.dll.
When we are going to create a Subflow, we add a record to the FlowSubFlow table in the eBA database, this insert process makes the Process Sub-flow. We perform this operation with the AddSubFlow function.
When starting a subflow, we can send data from the main process as a parameter, and we can also obtain the id information of the initiated substream directly on the main process.
In order to send data to the substream with a parameter, the variable must be defined in the flow form of the sub-process and marked as public.
References to add
%SystemPath%\Common\eBAPI.dll
%SystemPath%\Common\eBADB.dll
Namespace to add
using eBAPI;
using eBAPI.Connection;
using eBADB;
using eBAPI.Workflow;
using System.Data.SqlClient;
using System.Data;
public void fn_StartSubFlow_Execute()
{
using (eBAConnection con = CreateServerConnection())
{
Con. open();
eBAForm frm = Document1.ProfileData;
WorkflowProcess mgr = con. WorkflowManager.CreateProcess(process: "SubFlow"); We enter the name of the Flow to be started
Mgr. Parameters.Add("varFlowStarter", FlowStarter1.User); The user Id information that started the main flow is added as a parameter to be sent to the public variable in the subflow.
Mgr. Parameters.Add("varMainFlowId", id.ToString()); The main stream id value is added as a parameter to be sent to the public variable in the child stream.
Mgr. Parameters.Add("varMainFlowFormId", Document1.ProfileId.ToString()); The form id value in the main process is added as a parameter to be sent to the public variable in the substream.
Mgr. Parameters.Update();
Mgr. Start(); Initiating the substream
frm. Fields["txtSubFlowId"]. AsString = mgr. ProcessId.ToString(); Print the id of the initiated Subflow to the TextBox in the main form
frm. Fields["txtMainFormPath"]. AsString = new eBAForm(int. Parse(Document1.ProfileId.ToString())). ProfileOwner;
frm. Update();
For Insert Database
AddSubFlow(triggeredId: mgr. ProcessId, orderNo: GetOrderID(mgr. ProcessId), Description: id.ToString() + " id over stream " + mgr. ProcessId.ToString() + "id substream Initialized");
}
}
private int GetOrderID(int AkisID) //here we pass the id of the main flow as a parameter.
{
eBADBProvider SqlCon = CreateDatabaseProvider();
SqlCon.Open();
Try
{
string Sql = "Select Max(ORDERNO) AS ORDERNO From FLOWREQUESTS Where ProcessId=" + AkisID;
SqlDataAdapter = (SqlDataAdapter) SqlCon.CreateDataAdapter(Sql);
DataTable dt = new DataTable();
also. Fill(dt);
if (dt. Rows.Count ```>``` 0)
{
return int. Parse(dt. rows[0]["ORDERNO"]. ToString());
}
else
{
throw new Exception("Query Contains No Rows :\n" + Sql);
}
}
catch (Exception e)
{
throw new Exception(e.Message);
}
finally
{
SqlCon.Close();
}
}
private void AddSubFlow(int triggeredId, int orderNo, string Description)
{
eBAConnection con = CreateServerConnection();
Con. open();
We assign a record to the SubFlow Table, we need to call this function when we create a subflow
string sql = string. format(@"INSERT INTO FLOWSUBFLOWS(PROCESSID,SUBPROCESSID,ORDERID,DESCRIPTION,RELATIONDATE,RELATIONTYPE) VALUES('" + id.ToString() + "','" + triggeredId + "','" + orderNo + "','" + Description + "',getdate(),'1')");
ORDERNO is hardcoded from the last step in the main stream.
Give relation type 1
eBADB.eBADBProvider db = CreateDatabaseProvider();
SqlConnection = SqlCon (SqlConnection)db. Connection;
SqlCon.Open();
Try
{
SqlCommand com = new SqlCommand(sql, SqlCon);
com. ExecuteNonQuery();
com. Dispose();
}
finally
{
SqlCon.Close();
Con. Close();
}
}
Sample flow design for sub-process
In order to get data from the parent stream with a parameter, the variable must be defined in the flow form of the sub-process and marked as public.
In this example; The Flow Initiator object, which was added by default in the child flow form, has been removed and replaced with a position object. Therefore, the default Creator selection in the Document creation object has been revised. It is ensured that data is received from the upper flow and operations are performed on the function object placed before the position object.
public void Fonksiyon1_Execute()
{
eBAForm frm = new eBAForm(Document1.ProfileId);
frm. Fields["txtMainFlowStarter"]. AsString = varFlowStarter.Value;
frm. Fields["txtMainFlowId"]. AsString = varMainFlowId.Value;
frm. Fields["txtMainFlowFormId"]. AsString = varMainFlowFormId.Value;
frm. Update();
}