cancel
Showing results for 
Search instead for 
Did you mean: 

Facing issue with Task complete event

ganeshr
Champ in-the-making
Champ in-the-making
I'm publishing some events to notify user about task completion whenever a task complete event is fired using task listener . I'm using formService.submitTaskFormData(taskId, formVariables); to complete the task.

in some cases  after the compelte event is getting fired, task is not getting completed due to some error in the business process and getting rollbacked. Due to this whatever my business logic to send/notify users about task complete is getting executed eventhough task is not completed which is not the right way.
Is the task complete event fires after task is compelted or whenever a task is about to be completed? can we fire task comeplete event only after task is completed successfully? can any one suggest..
3 REPLIES 3

frederikherema1
Star Contributor
Star Contributor
I'm afraid there is no built-in solution for this. After completing the task, it's possible that a load of other operations occur (service-tasks, …) in the same transaction. Only when the process reached a wait-state/async/process-end, the transaction will be comitted. The event you get when completing is indeed only valid if the transaction commits.

As a solution, I whould suggest keeping the task-ID (or whatever data you need) somewhere in a thread-local. Add a transaction-listener to the ongoing transaction (depends on your transaction implementation. For Spring, use a TransactionSynchronizationAdapter) that is called on commit and sends out any notifications at that moment.

You can also piggy-back on the activiti generalisation of these listeners if you don't want to dig deep into transaction-management, see the class org.activiti.engine.impl.cfg.TransactionContext, which you can obtain an IMPL from by using org.activiti.engine.impl.interceptor.CommandContext.getTransactionContext(). The context allows adding a listener - Please note that this is "internal" activiti stuff and CAN change in the future. However, it's a safe bet to say that transaction-behaviour won't be very likely to change in the future Smiley Wink

In case if we have next opertation like(Service task) after the user task and which is async. Can the user task transaction is commited after the complete event is fired eventhough if service task invocation fails?
Is User task complete event fired after the task is completed or just before the task is about to be completed?

jbarrez
Star Contributor
Star Contributor
If async point is encountered, the transaction is committed, with the listener firing included. It is only the service task that is handled async.