How to set and pass variables to Task listener class using Flowable Designer in spring

Hi ,

I want to send an email when task is assigned to a user kind of email notification. So I was thinking to attach a task listener create event on the usertask and select a java class file with sending an email implementation. But I don’t know what should I put in fields. I want to call function sendEmail(to, subject, text) with these parameters from that email class. How do I set these parameters in spring and call this function with these parameters. Is my approach correct??? May be there could be a better approach please help.

Awaiting for any help…

Hi,

Then you want to use the assignment event with a task listener instead of a create event. The task listener should look like this:

<flowable:taskListener event=“assignment” expression="${myBean.sendEmail(to, subject, text)}" />

or

<flowable:taskListener event=“assignment” expression="${myBean.sendEmail(execution)}" />

With the last approach, you can determine the to, subject and text values using the process instance execution or within your own Java logic.

Best regards,

Tijs

Thank you so much for the quick response.

Few doubts though,

  1. In the first approach myBean is the classname ?? and to, subject and text… variables can be set through variables.put(“to”, "alex@gmail.com"); ???
  2. I din’t get execution in the second approach. if you could shed some light on that will be helpful.

Hi,

I thought you wanted to use a Spring bean, so myBean would be the Spring bean.
For more details you can read the docs here (http://www.flowable.org/docs/userguide/index.html#taskListeners).
Yes, the to, subject and text should be variables.
execution is a reserved keyword that you can send as input parameter and you the use a DelegateExecution instance as parameter in the sendEmail method. On a DelegateExecution you can get all the process instance variables as well, in addition to process instance id etc.

Best regards,

Tijs

thank you so much. actually i have recently started learning spring and need workflow integration.

keep up the good work.

I tried with the first approach and I am getting an error

@Autowired
private EmailServiceImpl emailServiceImpl;

variables.put(“to”, “abc@gmail.com”);
variables.put(“subject”, “test mail”);
variables.put(“text”, “testing text of email”);
variables.put(“emailServiceImpl”, emailServiceImpl);

Task listener expression: ${emailServiceImpl.sendEmail(to, subject, text)}

“errorMessage”: “couldn’t find a variable type that is able to serialize com.test.demo.utils.EmailServiceImpl@66c9b29f”

I must be doing in wrong way…Please guide me

Awaiting for response

Hi,

You are not using a Spring bean but try to serialize a non serializable class as a variable.
If you just have a Java class then you can use:

<flowable:taskListener event=“assignment” class=“org.flowable.YourClass” />

You can also find this in the documentation link I pasted in an earlier post.

Best regards,

Tijs