How to get TaskService in a class that implements taskListener

cancel
Showing results for 
Search instead for 
Did you mean: 
chiranjeev
Member II

How to get TaskService in a class that implements taskListener

Greetings to All, Anyone know how to get  taskService service reference in a class that implements the  TaskListener to create an attachment.  

If anyone can help it would be greatly appreciate.

2 Replies
afaust
Master

Re: How to get TaskService in a class that implements taskListener

If you look at the API of the DelegateTask you are passed in the listener, you will see that you can get a DelegateExecution via getExecution(), which in turn allows you to retrieve EngineServices via getEngineServices() - and if you look at that API, it allows you to retrieve various services, among them the TaskService.

Additionally, if you are developing in APS or another context with an annotation-based Spring dependency injection environment, you can simply have Spring inject the TaskService via @Autowired (provided you set your listener up to be a bean via @Component and access it via a delegate expression in your processes instead of a using it as a simple class-based listener).

Also note that, if you are working in APS, attachments are not handled via the TaskService. APS is a hack bolted on top of the core Activiti engine and it has its own RelatedContentService for dealing with attachments.

chiranjeev
Member II

Re: How to get TaskService in a class that implements taskListener

I have a file prepared and that has to be displayed in "Display Value" filed in the form.
Process:
1.File will be prepared based on some business logic
2.I want to write a listener class which attaches the prepared file to a particular task
3.finally i want to display the attached file in "Display Value" field in the form as mentioned above

any help will be would be greatly appreciate.