Ali
Ali

Reputation: 478

How to use Elsa workflow with TriggereSignal activity and UserTask activity [elsa-workflows]?

Elsa is a very capable workflow engine with a dashboard. I have read documentation and go through on basic tutorials, which are working fine. But there is very limited help. Only four basic samples.

I think TriggereSignal is supposed to be used to trigger a blocking Signal Activity but I am unable to trigger a signal.

Can some one provide me a sample of TriggereSignal and UserTask. I would like Json sample

Upvotes: 1

Views: 1813

Answers (3)

Sesethu Mhlana
Sesethu Mhlana

Reputation: 51

I can give you an example of the SignalReceived activity, but I don't know about UserTask.

I am using the SignalReceived activity to start my workflows. I place it at the beginning of all my workflows and set the signal value to the WorkflowDefinitionId, which you can get from the URL like this:

SignalReceived activity

Then from the code I can trigger the activity like this:

var collectedWorkflows = await _signaler.TriggerSignalAsync(workflowDefinitionId, input: signalInput);

var collectedWorkflowsList = collectedWorkflows.ToList();

You can use collectedWorkflowsList as you see fit, but the workflow will be triggered at this point.

workflowDefinitionId is the id I copied from the URL, but in this case I am fetching it from the database. signalInput is just an object I create, you can pass in anything you like.

I also use it to trigger a blocking signal. Place the activity in your workflow where you want to block the workflow and set the value to anything you want. You will use this value to target that signal. This is the code:

var triggeredWorkflow = await _signaler.TriggerSignalAsync(<TRIGGER_VALUE>, input: signalInput, workflowInstanceId: workflowInstanceId);

Upvotes: 0

MD Zand
MD Zand

Reputation: 2615

OK here is how it is possible after trigger changes made to Elsa:

public async Task<IActionResult> SendSignalToInstance(string workflowInstanceId, string userAction)
        {
           
            var wfInstanceDef = await _instanceStore.FindAsync(new EntityIdSpecification<WorkflowInstance>(workflowInstanceId));
            var currentActivityId = wfInstanceDef.BlockingActivities.FirstOrDefault().ActivityId;
             await _workflowStorageService.UpdateInputAsync(wfInstanceDef, new WorkflowInput(userAction));              
            var runres = await _wfTriggerInterruptor.InterruptActivityAsync(wfInstanceDef, currentActivityId);
            return Ok(runres.Executed);

        }

Upvotes: 0

MD Zand
MD Zand

Reputation: 2615

In 2.4.0 I could do so like this. But unfortunately the 'InterruptActivityAsync' method in IWorkflowTriggerInterruptor signature is changed in 2.7. So if you are using 2.4.x this would work. If I found a way in 2.7 version I will share it here

public async Task<IActionResult> SendSignalToInstance(string workflowInstanceId, string userAction)
        {
           
            var wfInstanceDef = await _instanceStore.FindAsync(new EntityIdSpecification<WorkflowInstance>(workflowInstanceId));
            var currentActivityId = wfInstanceDef.BlockingActivities.FirstOrDefault().ActivityId;
                           
            var runres = await _wfTriggerInterruptor.InterruptActivityAsync(wfInstanceDef, currentActivityId, new WorkflowInput(userAction));
            return Ok(runres.Executed);

        }

Upvotes: 0

Related Questions