Genpact Cora Knowledge Center

Support

Start a New Workflow Instance

Use the API to start a new workflow instance.

//***************************************************
//
// Copyright (C) PNMsoft. All rights reserved.
// 
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//***************************************************
 
using System;
using System.Collections.Generic;
using PNMsoft.Sequence;
using PNMsoft.Sequence.Runtime;
 
namespace SequenceEx.Runtime.Samples
{
 class StartWorkflowSample
 {
 /// <summary>
 /// Starts a new workflow instance.
 /// </summary>
 /// <param name="workflowId">The ID of the workflow to start.</param>
 /// <returns>A new workflow instance.</returns>
 private static WorkflowInstance CreateWorkflowInstance(Guid workflowId)
 {
 IWorkflowExecutionService svc = WorkflowRuntime.Engine.GetService<IWorkflowExecutionService>();
 return svc.StartWorkflow(workflowId);
 }
 
 /// <summary>
 /// Starts a new workflow instance.
 /// </summary>
 /// <param name="workflowId">The ID of the workflow to start.</param>
 /// <param name="parameters">The dictionary that contains workflow variables initialization values.</param>
 /// <returns>A new workflow instance.</returns>
 public WorkflowInstance StartWorkflowInstanceWithParameters(Guid workflowId, Dictionary<string, object> variables)
 {
 IWorkflowExecutionService svc = WorkflowRuntime.Engine.GetService<IWorkflowExecutionService>();
 return svc.StartWorkflow(workflowId, variables);
 }
 }
}