How to set the ScriptTaskListener as a Task Listener class on the Activiti App Designer

A task listener gives you a lot of flexibility and an ideal advantage around the task life cycle. It can be added as part of a user task only. You can do it through an Expression, a Delegate Expression or a Class. Expression and Delegate Expression require deploying your custom beans in APS. You can create your own task listener class implementing the interface org.activiti.engine.delegate.TaskListener, but that also requires to deploy your customization into Alfresco Process Services.

There’s a much easier way to set a task listener and execute your code using the ScriptTaskListener (available since version 5.12) without deploying a customization, just from the APS Visual Editor. The steps are described as follows,

1. Access the process model from the Visual Editor

2. Select the user task that will be associated with the task listener

3. Click on the Task Listeners option

4. Click on the add (+) button from the top table

5. Set the event (create, assignment, complete, delete)

6. Enter the Class org.activiti.engine.impl.bpmn.listener.ScriptTaskListener
You may find in the Alfresco documentation that you can use the class org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener to set it as a TaskListener. This one is related to the Activiti embedded in Alfresco Content Services. It provides the same access and functionality but it doesn’t exist on Alfresco Process Services with that package, so you won’t be able to use it on APS.

7. Click on the add (+) button from the bottom table

8. Enter in the field Name the value language

9. Enter in the field String value the script language that you want to use (i.e javascript, groovy)

10. Add another entry on the same table

11. Enter in the field Name the value script

12. Enter in the field String the script code for your task listener.

Note: You can get access to the task through the object task and to the execution through the method task.getExecution()

Leave a Reply

Your email address will not be published. Required fields are marked *