cancel
Showing results for 
Search instead for 
Did you mean: 

Delete task listener and Complete task listener problem

yahekia
Champ in-the-making
Champ in-the-making
Hi there,


I am having a couple of problems with a delete listener, here is some background about this issue. I am using Activiti 5.13, and I have a complete task listener and a delete task listener, I also have a task service that ends all processes that share the same property value:


@Override
    public void execute(DelegateExecution execution) throws Exception {
        int myPropertie= (Integer) execution.getVariable("myPropertie");
        final RuntimeService runtimeService = execution.getEngineServices().getRuntimeService();
        List<Execution> executions = runtimeService.createExecutionQuery().variableValueEquals("myPropertie", myPropertie)
                .list();

        for (Execution ex : executions) {
            runtimeService.deleteProcessInstance(ex.getProcessInstanceId(), "my delete reason");
        }

    }


The first problem is that both listeners are being fired, I think this should not be happening but I do not know if it is coded that way for some reason.

The second problem is that I do not have any way to get the delete reason in the delegate task neither in the taskhistory instance, Is there  any place where I can get the value¿¿??

Thanks for your time.

Javi.
4 REPLIES 4

jbarrez
Star Contributor
Star Contributor
"The first problem is that both listeners are being fired, I think this should not be happening but I do not know if it is coded that way for some reason."

Yes, a task will first be completed before it is deleted from the runtime table. If you're not interested in the delete event, simply don't listen to it.

"The second problem is that I do not have any way to get the delete reason in the delegate task neither in the taskhistory instance, Is there any place where I can get the value¿¿??"

The delete reason is not yet flushed to the database at that point.
Afterwards you can get it from the HistoricTaskInstance:

<code>
  /** The reason why this task was deleted {'completed' | 'deleted' | any other user defined string }. */
  String getDeleteReason();
</code> 

yahekia
Champ in-the-making
Champ in-the-making
It is not so simply because what I want is to diferenciate when a task has been completed normally or has been deleted by an user action(my code), and I need it to be known in the listener because in that point we are indexing the task in an external index

Why you can not suppose that when a task is completed is deleted from the runtime table? I do not see the reason to fire both events, can you explain it to me??  I really want to understand if I am doing something wrong or assuming things that are not supossed to be that way.

Thnx!



trademak
Star Contributor
Star Contributor
The reason is mainly a technical one. Maybe you can add logic to a delete listener for the exception use case and add a service task after the user task for the "completed normally" use case?

Best regards,

jbarrez
Star Contributor
Star Contributor
"Why you can not suppose that when a task is completed is deleted from the runtime table? I do not see the reason to fire both events, can you explain it to me?"

Cause some people will only care about the delete event, not the complete.
Taks (standalone tasks especially) can be deleted from the api, without being completed for example.