# How to use triggerable

**URL:** https://forum.flowable.org/t/how-to-use-triggerable/3016
**Category:** Flowable Engine
**Created:** [December 10, 2018, 4:00pm UTC](https://forum.flowable.org/t/how-to-use-triggerable/3016 "2018-12-10T16:00:21Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![asterisk](https://avatars.discourse-cdn.com/v4/letter/a/6a8cbe/32.png) [@asterisk](https://forum.flowable.org/u/asterisk)
#### Post date: [December 10, 2018, 4:00pm UTC](https://forum.flowable.org/t/how-to-use-triggerable/3016/1 "2018-12-10T16:00:21Z")

</div>

Hi, I want to use serviceTask with triggerable and async.But I don’t know how to use it, can anybody give me an example?

I’m confused:

1. Why “step\_one” can not be executed after startProcessInstanceByKey has been called.
2. If I set “step\_one” flowable:async=“false”, the execution variable is null. If set async=“true”, the execution variable is not null (code like this:)

> Deployment deployment = repositoryService.createDeployment().addClasspathResource(“bpmn/SendEvent.bpmn”).deploy();  
> ProcessInstance pi = runtimeService.startProcessInstanceByKey(“SendEvent”);  
> Execution execution = runtimeService.createExecutionQuery()  
> .processInstanceId(pi.getId())  
> .activityId(“step\_one”)  
> .singleResult();  
> assertNotNull(execution);  
> Thread.sleep(5000);  
> runtimeService.triggerAsync(execution.getId());  
> Thread.sleep(5000);

1. after triggerAsync called, nothing happened. “sendEventService.sendMessage” has been called.

My bpmn like this:

> \<?xml version=“1.0” encoding=“UTF-8”?\>  
> \<definitions xmlns=“[http://www.omg.org/spec/BPMN/20100524/MODEL"&#32;xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”&#32;xmlns:xsd=“http://www.w3.org/2001/XMLSchema”&#32;xmlns:flowable=“http://flowable.org/bpmn”&#32;xmlns:bpmndi=“http://www.omg.org/spec/BPMN/20100524/DI”&#32;xmlns:omgdc=“http://www.omg.org/spec/DD/20100524/DC”&#32;xmlns:omgdi=“http://www.omg.org/spec/DD/20100524/DI”&#32;typeLanguage=“http://www.w3.org/2001/XMLSchema”&#32;expressionLanguage=“http://www.w3.org/1999/XPath”&#32;targetNamespace="http://www.flowable.org/processdef](http://www.omg.org/spec/BPMN/20100524/MODEL%22&#32;xmlns:xsi=%22http://www.w3.org/2001/XMLSchema-instance%22&#32;xmlns:xsd=%22http://www.w3.org/2001/XMLSchema%22&#32;xmlns:flowable=%22http://flowable.org/bpmn%22&#32;xmlns:bpmndi=%22http://www.omg.org/spec/BPMN/20100524/DI%22&#32;xmlns:omgdc=%22http://www.omg.org/spec/DD/20100524/DC%22&#32;xmlns:omgdi=%22http://www.omg.org/spec/DD/20100524/DI%22&#32;typeLanguage=%22http://www.w3.org/2001/XMLSchema%22&#32;expressionLanguage=%22http://www.w3.org/1999/XPath%22&#32;targetNamespace=%22http://www.flowable.org/processdef)”\>  
> \<process id=“SendEvent” name=“SendEvent” isExecutable=“true”\>  
> \<startEvent id=“startEvent1”\>\</startEvent\>  
> \<serviceTask id=“step\_one” name=“step\_one\_name” flowable:async=“true” flowable:triggerable=“true” flowable:expression=“#{sendEventService.sendMessage(execution, ‘test\_app’, ‘test\_firstEvent’)}”\>\</serviceTask\>  
> \<sequenceFlow id=“sid-C43EA3A5-7F38-48B8-B091-112C6632B064” sourceRef=“startEvent1” targetRef=“step\_one”\>\</sequenceFlow\>  
> \<serviceTask id=“step\_two” name=“step\_two\_name” flowable:async=“false” flowable:triggerable=“true” flowable:expression=“#{sendEventService.sendMessage(execution, ‘test\_app’, ‘test\_secondEvent’)}”\>\</serviceTask\>  
> \<sequenceFlow id=“sid-AD35CE48-AB59-4C40-9DA1-91B21F1463F9” sourceRef=“step\_one” targetRef=“step\_two”\>\</sequenceFlow\>  
> \<endEvent id=“sid-FDDCC035-C01D-41D2-9867-39D78F064B50”\>\</endEvent\>  
> \<sequenceFlow id=“sid-370A3246-FDBA-467E-86F4-BB131A80DB69” sourceRef=“step\_two” targetRef=“sid-FDDCC035-C01D-41D2-9867-39D78F064B50”\>\</sequenceFlow\>  
> \</process\>  
> \<bpmndi:BPMNDiagram id=“BPMNDiagram\_SendEvent”\>  
> \<bpmndi:BPMNPlane bpmnElement=“SendEvent” id=“BPMNPlane\_SendEvent”\>  
> \<bpmndi:BPMNShape bpmnElement=“startEvent1” id=“BPMNShape\_startEvent1”\>  
> \<omgdc:Bounds height=“30.0” width=“30.0” x=“100.0” y=“163.0”\>\</omgdc:Bounds\>  
> \</bpmndi:BPMNShape\>  
> \<bpmndi:BPMNShape bpmnElement=“step\_one” id=“BPMNShape\_step\_one”\>  
> \<omgdc:Bounds height=“80.0” width=“100.0” x=“257.0” y=“135.0”\>\</omgdc:Bounds\>  
> \</bpmndi:BPMNShape\>  
> \<bpmndi:BPMNShape bpmnElement=“step\_two” id=“BPMNShape\_step\_two”\>  
> \<omgdc:Bounds height=“80.0” width=“100.0” x=“506.0” y=“130.0”\>\</omgdc:Bounds\>  
> \</bpmndi:BPMNShape\>  
> \<bpmndi:BPMNShape bpmnElement=“sid-FDDCC035-C01D-41D2-9867-39D78F064B50” id=“BPMNShape\_sid-FDDCC035-C01D-41D2-9867-39D78F064B50”\>  
> \<omgdc:Bounds height=“28.0” width=“28.0” x=“690.0” y=“156.0”\>\</omgdc:Bounds\>  
> \</bpmndi:BPMNShape\>  
> \<bpmndi:BPMNEdge bpmnElement=“sid-AD35CE48-AB59-4C40-9DA1-91B21F1463F9” id=“BPMNEdge\_sid-AD35CE48-AB59-4C40-9DA1-91B21F1463F9”\>  
> \<omgdi:waypoint x=“356.9499999999986” y=“173.995983935743”\>\</omgdi:waypoint\>  
> \<omgdi:waypoint x=“505.99999999999847” y=“171.00301204819277”\>\</omgdi:waypoint\>  
> \</bpmndi:BPMNEdge\>  
> \<bpmndi:BPMNEdge bpmnElement=“sid-370A3246-FDBA-467E-86F4-BB131A80DB69” id=“BPMNEdge\_sid-370A3246-FDBA-467E-86F4-BB131A80DB69”\>  
> \<omgdi:waypoint x=“605.95” y=“170.0”\>\</omgdi:waypoint\>  
> \<omgdi:waypoint x=“690.0” y=“170.0”\>\</omgdi:waypoint\>  
> \</bpmndi:BPMNEdge\>  
> \<bpmndi:BPMNEdge bpmnElement=“sid-C43EA3A5-7F38-48B8-B091-112C6632B064” id=“BPMNEdge\_sid-C43EA3A5-7F38-48B8-B091-112C6632B064”\>  
> \<omgdi:waypoint x=“129.9482124561182” y=“177.76565302378518”\>\</omgdi:waypoint\>  
> \<omgdi:waypoint x=“256.9999999999982” y=“175.78046875000004”\>\</omgdi:waypoint\>  
> \</bpmndi:BPMNEdge\>  
> \</bpmndi:BPMNPlane\>  
> \</bpmndi:BPMNDiagram\>  
> \</definitions\>

---

<div class="post-metadata">

### Author: ![jorge.mora](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/jorge.mora/32/694_2.png) [@jorge.mora](https://forum.flowable.org/u/jorge.mora)
#### Post date: [December 10, 2018, 5:31pm UTC](https://forum.flowable.org/t/how-to-use-triggerable/3016/2 "2018-12-10T17:31:27Z")

</div>

Hi,

The “triggerable” setting currently works for a Java delegate implementing the TriggerableActivityBehavior interface.

Please, have a look at this unit test:

> <https://github.com/flowable/flowable-engine/blob/master/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/servicetask/TriggerableServiceTaskTest.java>

Also, to the associated process diagram

> <https://github.com/flowable/flowable-engine/blob/master/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/servicetask/TriggerableServiceTaskTest.testAsyncJobs.bpmn20.xml>

I hope this helps to clarify the triggerable service task .

Regards,  
Jorge Mora.

---

<div class="post-metadata">

### Author: ![wberges](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/wberges/32/940_2.png) [@wberges](https://forum.flowable.org/u/wberges)
#### Post date: [December 11, 2018, 8:40am UTC](https://forum.flowable.org/t/how-to-use-triggerable/3016/3 "2018-12-11T08:40:09Z")

</div>

Hello,  
You can have a look at this topic:

> [@Camel usable outside Camel Task? (e.g. in JavaDelegate or Expression)](https://forum.flowable.org/t/camel-usable-outside-camel-task-e-g-in-javadelegate-or-expression/2967):
>
> Hello, Is there a way to retrieve a Camel object (bean?) or the flowable camel context outside a Camel Task? Either in a JavaDelegate (of a Service Task for example) or in an Expression (in the Expression field of a Service Task using #{camel.callRoute(‘direct:myRoute’)}) for example? The use-case could be to have a triggerable Service Task (not available for a Camel Task for now) using camel in its JavaDelegate (simulates a triggerable Camel Task) or in its Expression. Thanks Best Regards …

HTH  
Best Regards  
William

---

<div class="post-metadata">

### Author: ![asterisk](https://avatars.discourse-cdn.com/v4/letter/a/6a8cbe/32.png) [@asterisk](https://forum.flowable.org/u/asterisk)
#### Post date: [December 11, 2018, 2:38pm UTC](https://forum.flowable.org/t/how-to-use-triggerable/3016/4 "2018-12-11T14:38:53Z")

</div>

Thank you for reply. I got it. My UT is passed 🙂

---

<div class="post-metadata">

### Author: ![reshmo](https://avatars.discourse-cdn.com/v4/letter/r/b5e925/32.png) [@reshmo](https://forum.flowable.org/u/reshmo)
#### Post date: [December 16, 2019, 7:34am UTC](https://forum.flowable.org/t/how-to-use-triggerable/3016/5 "2019-12-16T07:34:36Z")

</div>

@ jorge.mora With reference to your mention about triggerable works only for Java delegate, can you please let me know how to use triggerable for a http service task . I don’t have any java classes . Everything is handled in bpmn alone. Also in flowable doc there is no detailed explanation about trigger can be used with only java delegate implementing the TriggerableActivityBehavior. Can you throw some pointers on this. Thanks in advance

---

<div class="post-metadata">

### Author: ![jorge.mora](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/jorge.mora/32/694_2.png) [@jorge.mora](https://forum.flowable.org/u/jorge.mora)
#### Post date: [December 16, 2019, 8:26am UTC](https://forum.flowable.org/t/how-to-use-triggerable/3016/6 "2019-12-16T08:26:48Z")

</div>

I think that you can have a look at [the answer](https://forum.flowable.org/t/camel-usable-outside-camel-task-e-g-in-javadelegate-or-expression/2967/5) from @pstapleton for Camel tasks. You can try creating your own ActivityBehavior based on the original HttpActivityBehavior and add the triggerable behavior. I have not tried that by myself but it must work.

---

<div class="post-metadata">

### Author: ![reshmo](https://avatars.discourse-cdn.com/v4/letter/r/b5e925/32.png) [@reshmo](https://forum.flowable.org/u/reshmo)
#### Post date: [December 18, 2019, 4:57am UTC](https://forum.flowable.org/t/how-to-use-triggerable/3016/7 "2019-12-18T04:57:10Z")

</div>

Thank you Jorge! I will try with your approach .

---

<div class="post-metadata">

### Author: ![donkon](https://avatars.discourse-cdn.com/v4/letter/d/f475e1/32.png) [@donkon](https://forum.flowable.org/u/donkon)
#### Post date: [February 18, 2020, 3:09pm UTC](https://forum.flowable.org/t/how-to-use-triggerable/3016/8 "2020-02-18T15:09:05Z")

</div>

Will there be support for serviceTasks with expressions? We heavily rely on expressions (${bean.method()}) and would also need the triggerable flag.

---

<div class="post-metadata">

### Author: ![donkon](https://avatars.discourse-cdn.com/v4/letter/d/f475e1/32.png) [@donkon](https://forum.flowable.org/u/donkon)
#### Post date: [February 18, 2020, 5:03pm UTC](https://forum.flowable.org/t/how-to-use-triggerable/3016/9 "2020-02-18T17:03:31Z")

</div>

As I see, the `org.flowable.engine.impl.bpmn.behavior.ServiceTaskExpressionActivityBehavior`  
class does not use the triggerable attribute. Would it be fine to just not call `leave` when triggerable is true (in execute()) and do nothing in trigger()?

---

<div class="post-metadata">

### Author: ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)
#### Post date: [February 19, 2020, 7:23am UTC](https://forum.flowable.org/t/how-to-use-triggerable/3016/10 "2020-02-19T07:23:48Z")

</div>

@donkon, that would most certainly be doable. However, how do you plan do call the trigger method? In order to trigger an instance you would need to know the `executionId`

---

<div class="post-metadata">

### Author: ![donkon](https://avatars.discourse-cdn.com/v4/letter/d/f475e1/32.png) [@donkon](https://forum.flowable.org/u/donkon)
#### Post date: [February 19, 2020, 7:43am UTC](https://forum.flowable.org/t/how-to-use-triggerable/3016/11 "2020-02-19T07:43:54Z")

</div>

I have the executionId and would use the `runtimeService.trigger()` method. Would that work?

---

<div class="post-metadata">

### Author: ![donkon](https://avatars.discourse-cdn.com/v4/letter/d/f475e1/32.png) [@donkon](https://forum.flowable.org/u/donkon)
#### Post date: [February 20, 2020, 1:41pm UTC](https://forum.flowable.org/t/how-to-use-triggerable/3016/12 "2020-02-20T13:41:33Z")

</div>

@filiphr it works this way:

```
public class ServiceTaskExpressionTriggerableActivityBehavior extends ServiceTaskExpressionActivityBehavior {

/** Serial. */
private static final long serialVersionUID = 9175468903749206291L;

private boolean triggerable;

public ServiceTaskExpressionTriggerableActivityBehavior(ServiceTask serviceTask, Expression expression, Expression skipExpression) {
	super(serviceTask, expression, skipExpression);
	this.triggerable = serviceTask.isTriggerable();
}

@Override
public void trigger(DelegateExecution execution, String signalName, Object signalData) {
	super.leave(execution);
}

@Override
public void leave(DelegateExecution execution) {
	if (!this.triggerable) {
		super.leave(execution);
	}
}

```

}

Could this functionality be integrated in the flowable code base (nothing special here)?

---

<div class="post-metadata">

### Author: ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)
#### Post date: [February 20, 2020, 8:25pm UTC](https://forum.flowable.org/t/how-to-use-triggerable/3016/13 "2020-02-20T20:25:19Z")

</div>

Thanks for the snippet @donkon. I think that adding support for `triggerable` in the `ServiceTaskExpressionTriggerableActivityBehavior`. Seems like you already know what needs to be done. Would you be interested in providing a PR with this addition?

---

<div class="post-metadata">

### Author: ![donkon](https://avatars.discourse-cdn.com/v4/letter/d/f475e1/32.png) [@donkon](https://forum.flowable.org/u/donkon)
#### Post date: [February 23, 2020, 10:25am UTC](https://forum.flowable.org/t/how-to-use-triggerable/3016/14 "2020-02-23T10:25:52Z")

</div>

> [@filiphr](#):
>
> Would you be interested in providing a PR with this addition?

sure:

> <https://github.com/flowable/flowable-engine/pull/2185>
>
> A ServiceTask with an expression should also be triggerable:
> 
> The org.flowable….engine.impl.bpmn.behavior.ServiceTaskExpressionActivityBehavior
> class would just not call leave when triggerable is true (in execute()) and leaves in trigger().
> 
> https://forum.flowable.org/t/how-to-use-triggerable/3016
> 
> \#### Check List:
> \* Unit tests: YES 
> \* Documentation: YES

---

<div class="post-metadata">

### Author: ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)
#### Post date: [February 24, 2020, 7:57am UTC](https://forum.flowable.org/t/how-to-use-triggerable/3016/15 "2020-02-24T07:57:50Z")

</div>

Thanks a lot @donkon. This has been merged into master.

---

<div class="post-metadata">

### Author: ![bipinbn](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/bipinbn/32/1719_2.png) [@bipinbn](https://forum.flowable.org/u/bipinbn)
#### Post date: [March 31, 2020, 10:32am UTC](https://forum.flowable.org/t/how-to-use-triggerable/3016/16 "2020-03-31T10:32:31Z")

</div>

Hi All,

We have a requirement where in we need to call custom java code from service task. This custom java code does some business logic. We want the process to wait when this happens and we plan to trigger the process again after our business logic is done.

I figured that using service task with **flowable:triggerable=“true” flowable:async=“true”** set. Below is the sample BPMN I have . This is just a POC which depicts what we want to achieve.

```
<?xml version="1.0" encoding="UTF-8"?>
<definitions typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.flowable.org/test" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:flowable="http://flowable.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI">
	<process id="ApprovalProcessSimple" isExecutable="true">
		
		<startEvent id="Start_Default"/>
		
		<serviceTask id="Start" flowable:delegateExpression="${serviceDelegate}">
			<extensionElements>
				<flowable:field name="taskDescription" stringValue="StartTask"/>
			</extensionElements>
		</serviceTask>

		<serviceTask id="ApprovedNode" flowable:delegateExpression="${asyncServiceDelegate}" flowable:triggerable="true" flowable:async="true">
			<extensionElements>
				<flowable:field name="taskDescription" stringValue="AsynNodeTaskTriggerSync"/>
			</extensionElements>
		</serviceTask>
		
			<serviceTask id="ConfirmNode" flowable:delegateExpression="${serviceDelegate}">
			<extensionElements>
				<flowable:field name="taskDescription" stringValue="ConfirmNode"/>
			</extensionElements>
		</serviceTask>
		
		<endEvent id="End"/>
		
		<sequenceFlow sourceRef="Start_Default" targetRef="Start"/>
		<sequenceFlow sourceRef="Start" targetRef="ApprovedNode"/>
		<sequenceFlow sourceRef="ApprovedNode" targetRef="ConfirmNode"/>
		<sequenceFlow sourceRef="ConfirmNode" targetRef="End"/>
	</process>
	<bpmndi:BPMNDiagram id="BPMNDiagram_ApprovedNodeManually">
		<bpmndi:BPMNPlane bpmnElement="ApprovedNodeManually" id="BPMNPlane_ApprovedNodeManually"/>
	</bpmndi:BPMNDiagram>
</definitions>

```

**The delegate for async task is :**

@Component  
public class AsyncServiceDelegate implements TriggerableActivityBehavior, JavaDelegate, Serializable {

```
private static final long serialVersionUID = 1L;

private final Logger logger = LoggerFactory.getLogger(AsyncServiceDelegate.class);

private Expression taskDescription;

@Override
public void execute(DelegateExecution execution) {

    String taskDescriptionValue = ((String) taskDescription.getValue(execution));
    logger.debug(LogMarker.ENTRY, "In execute method of AsynServiceDelegate");
    logger.debug("Current activity id is : {} ", execution.getCurrentActivityId());
    logger.debug("Current task descrption is {}", taskDescriptionValue);
    logger.debug("Current process id is : {}", execution.getProcessInstanceId());
    logger.debug("Execution id is : {}", execution.getId());

}

@Override
public void trigger(DelegateExecution execution, String signalEvent, Object signalData) {
    logger.debug("In trigger code inside delegate");

}

```

After we deploy and start the process and I see that the process reaches  
till **AsyncServiceDelegate** and does **execute()** and goes to wait state. It does not reach the **ConfirmNode** which is correct.

Now I am doing the below to trigger the process so that it continues execution . However this is not happening.

**Execution execution =**** runtimeService.createExecutionQuery().processInstanceId(processId).activityId(actvityId).singleResult();**  
**logger.debug("Execution id for triggering is : {} ", execution.getId());**  
**runtimeService.trigger(execution.getId());**

I see the call reaches **AsyncServiceDelegate.trigger()** method but nothing happens after that. How do I make the process continue to the **ConfirmNode**.

**a\> Is this because** **leave(execution)**  **is not called?**  
**b\> Will the above fix help us?**  
**c\> Is there a workaround for this if we are not able to take the above mentioned code fix?**

---

<div class="post-metadata">

### Author: ![joram](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/joram/32/26_2.png) [@joram](https://forum.flowable.org/u/joram)
#### Post date: [April 13, 2020, 11:27am UTC](https://forum.flowable.org/t/how-to-use-triggerable/3016/17 "2020-04-13T11:27:40Z")

</div>

> [@bipinbn](#):
>
> **Is this because** **leave(execution)**  **is not called?**

Correct. Once you implement one of the \*ActivityBehavior interface, you’re responsible for the routing logic (see the ‘internal’ section at [BPMN 2.0 Constructs · Flowable Open Source Documentation](https://flowable.com/open-source/docs/bpmn/ch07b-BPMN-Constructs/#implementation))
