How to attach tasklistener with java class

Hi,
I want to change data in my form when the user clicks “claim” .

I think this is possible via a tasklistener. I tried to attach the tasklistener class via the modeler:

Java Class:
public class ModifyDataAtClaimingMoment implements TaskListener{

@Override
public void notify(DelegateTask delegateTask) {
	delegateTask.setVariable("Var", "VarTest");
	delegateTask.setVariableLocal("localVar", "localVarTest");
	delegateTask.setVariable("thmUid", "testUID");
}

}

But I got the following error:

Caused by: org.camunda.bpm.engine.ProcessEngineException: ENGINE-09008 Exception while instantiating class '${modifyDataAtClaimingMoment.notify(task)': ENGINE-09017 Cannot load class '${modifyDataAtClaimingMoment.notify(task)': ${modifyDataAtClaimingMoment.notify(task) from [Module "deployment.ofv2.war" from Service Module Loader]

How can I do this?

The second question is, if it is the right way to change the process vars via: delegateTask.setVariable(“thmUid”, “testUID”);

I do not know if this works.
Thank you, Nicole

Instead of giving ‘${modifyDataAtClaimingMoment.notify(task)’ , give your class name that includes the package name. For example
com.mycompany.claim.ModifyDataAtClaimingMoment. This in turn will invoke your notify method

1 Like

In case you want to use CDI change Listener Type from Java Class to Expression.
Example from one of my processes:

<camunda:taskListener event="assignment" expression="${camundaCallback.sendNotificationEmailToAssignee(task)}"/>

with

@Named
public class CamundaCallback
...
public void sendNotificationEmailToAssignee( final Task task )
...
1 Like