Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Starting an Elsa workflow from a Workflow model in a controller

I am planning to use Elsa workflow for an enterprise application with acceptance flow (State machine). I am not sure about this process:
I have multiple workflow models designed by admin user. Each is related to a different entity. Now in the corresponding api controller I want to start a workflow for the entity.
The question is which libraries to inject to controller and use to create and instance and get the created instance id?

i.e.

public async Task<IActionResult> StartFlowOfSomeEntity(int entityID)
{
   //Is it the right way to load registry?
   var registeryList = await _workflowRegistry.ListAsync(CancellationToken.None);
   var relatedRegistery = registeryList.FirstOrDefault(uu => uu.Name == "MyFlowName");
   //Now need to create new instance?   
}

I am using UpdateInputAsync of WorkflowStorageService to apply outputs to the workflow instance.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried to use IWorkflowInstanceStore as sugested here but could not achieve the goal

>Solution :

WorkflowRegistery is the right way to load models. But I prefer to use another method of it:

var relatedRegistery = await _workflowRegistry.FindByNameAsync("MyFlowName", VersionOptions.Latest);

For creating workflow instances you should inject WorkflowStarter to your controller and then do this:

RunWorkflowResult workflowInstance = await _wfStarter.StartWorkflowAsync(relatedRegistery , null, null, null, entityID.ToString());

Then workflowInstance.WorkflowInstance.Id has the value of the instance id you want.

You can also see this code at github doing similar thing with Elsa.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading