Skip to main content

Synergy CSP Substream Initialization

The sample code for starting the substream can be found below. Note:

  • From the project named TEST, Flow1 of the project named TEST2 is started as a substream.
  • The TextBox object in the form that will come in front of the user in the starting subflow is assigned a value from the main flow.
  • With an assignment object in the starting subflow, the position object after the subflow starts is selected from the variable to which user the process will go. The value to be assigned to this variable is also sent to the substream in the following codes.
using System;
using Bimser.Synergy.Entities.Workflow.EventArguments;
using Bimser.CSP.Runtime.Common.Extensions;
using Bimser.Synergy.ServiceAPI;
using Bimser.Synergy.ServiceAPI.Models.Authentication;
using Newtonsoft.Json;
using Bimser.Synergy.Entities.Shared.Business.Objects;
using System.Threading.Tasks;
using Bimser.Synergy.ServiceAPI.Models.Workflow;
using Bimser.Synergy.Entities.Workflow.Runtime.Models.Controller;
namespace TEST. Flows
{
public partial class Flow1
{
protected LoginWithTokenAuthenticationParameters Credentials
{
Get
{
return new LoginWithTokenAuthenticationParameters
{
EncryptedData = _workflowData.Context.EncryptedData,
Language = _workflowData.Context.Language,
Token = _workflowData.Context.Token
};
}
}
internal static HttpClientOptions _httpClientOptions;
internal static string WebInterfaceUrl
{
Get
{
if (_httpClientOptions == null)
{
string envVar = Environment.GetEnvironmentVariable("HTTP_CLIENT_OPTIONS");
_httpClientOptions = JsonConvert.DeserializeObject<HttpClientOptions>(envVar);
}
return _httpClientOptions.WebInterfaceUrl;
}
}

private ServiceAPI _serviceApi;
protected ServiceAPI ServiceApi
{
Get
{
if(_serviceApi == null)
{
_serviceApi = new ServiceAPI(Credentials,WebInterfaceUrl);
}

return _serviceApi;
}
}
public async Task<WorkflowInstance> CreateProcess(string projectName, string flowName, long processId = 0)
{

return await ServiceApi.WorkflowManager.Create(projectName, flowName, processId);
}
public Task<FlowSaveAndContinueResponse> StartProcess()
{
var process = CreateProcess("TEST2", "Flow1", 0). Result;

Used to access the document of the substream
var form = process. Documents["Document1"]. FormInstance;
form. Controls["TextBox1"]. Value = "substream";
form. Save();
Causes the subflow to be initiated with the send event
process. StartingEvent = process. Events[4];
The processId of the main flow from which we started the subflow is sent
MainProcessId is the name of the public variable we defined in the substream
process. Variables["MainProcessId"] = _workflowData.General.ProcessId;
In the subflow, the userId of the user we want to approve is sent
VarUserId is the name of the public variable we defined in the substream
process. Variables["VarUserId"] = "2";//stream will fall on the ndale user

return process. SaveAndContinue();
}

public void FlowStart1_OnAfterExecution(object sender,OnAfterExecutionArguments args)
{
StartProcess();
}
}
}