cancel
Showing results for 
Search instead for 
Did you mean: 

Sending an email after user task is created

jim1
Champ on-the-rise
Champ on-the-rise
We have a scenario where when a user task is created, a TaskListener is fired (on create) which will create a temporary login for a user and then email them the login details along with the task ID.
We'd like to use a Mail Task to handle the email sending as the content can then be customised in the BPM, so we came up with the following pattern in the BPM:


Start —> Parallel Gateway —> User Task
                 |
                 |—-> Message Intermediate Catch Event —> Mail Task


The idea is that once the task listener has finished it's work, it will send the message that the catch event is listening for and the email will be sent.

However, when we query for the execution for the message catch event, no results are returned:


List<Execution> executions = runtimeService.createExecutionQuery()
            .messageEventSubscriptionName("LOGIN_CREATED")
            .processInstanceId(delegateTask.getProcessInstanceId()).list();

      if (executions != null && !executions.isEmpty()) {
         for (Execution e : executions) {
            runtimeService.messageEventReceived("LOGIN_CREATED", e.getId());
                    }
               }
         


I'm assuming that activiti is processing the branch from the parallel gateway to the user task first, so at this point the message catch event has not been created. Is there any way around this?

I've created a small unit tests which demonstrates the scenario:
https://drive.google.com/file/d/0Bz97E7VNAsowalBLOExFZmhlQms/view?usp=sharing

Thanks.
5 REPLIES 5

vasile_dirla
Star Contributor
Star Contributor
If I understood well your problem, another solution could be to create a custom behaviour for your user task.

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,
the easiest way how to get your example running is to make user task asynchronous.
See attached project.

Regards
Martin

jim1
Champ on-the-rise
Champ on-the-rise
Vasile - Thanks, will take a look into that as well.

Martin - Thanks very much for the reply. Could you check your file though please as it only seems to contain the folder and no source files.

** Update **
Actually, I've got it working by ticking the "Async" check box on the user task and enabling the async executer in the activiti config file.

Thanks for your help.

martin_grofcik
Confirmed Champ
Confirmed Champ
attachment update

thank