Add a task listener to all UserTasks


In our project - we are going to use our own logic and configuration to decide on the assignee or candidates for all UserTasks.

I wrote a Bean that can be used to return the list of users for a given task based on the taskDefId + a few additional parameters we set on the context and have in our configuration.

So far i have used it by setting the assignee/candidate on each UserTask as an expression that calls that method - and it works fine.

But in order to avoid the need to set it on each task - i wanted to add a task listener on all UserTasks - that will run on task create - and will call that logic and assign the values. This will save use setting the method on each task - give use flexibility (and avoid mistakes).

So i created my EngineConfigurationConfigurer - and in it i used setCustomDefaultBpmnParseHandlers
to set my UserTaskBpmnParseHandler which extends UserTaskParseHandler.

But inside my handler - i could not manage to add a new execution listener. I tried using different examples - but still could not make it work ( i do arrive inside the handler - just no listener added).

UserTask as a method of getTaskListener - but it returns a list of FlowableListener (and not TaskListener) - and did not know how to use it to add my listener.

Am i using a correct approach for this task - or is there a better way to achieve that ?
Is there any example i could use as reference on how to do that ?



I think you need to change the user task behaviour by defining your own UserTaskActivityBehavior implementation.

Thanks for the fast reply - will have a look at that option.
Do you know any example i can use as reference ?

Not sure, small description I found only here: Starting With Flowable As Developer

But for starterts, you need Spring Boot Flowable Engine in your application, and then you need to configure an appropriate bean which will be injected into the Engine. That’s all I know.

Ok - i managed to make it work using my approach of adding a listener on the create event.
In my UserTaskBpmnParseHandler i just created the FlowableListener (i used the FlowableListenerParser as a reference on how to set the fields) - and it works fine.
My Handler is called on each create of a UserTask - and it sets the required Assignee/Candidates

Thanks for help on this

1 Like