How can a user be notified by Camunda for a new created pending task?

Hi there.

I would like to ask how Camunda informs a user (or multiple users in the following case) about a new created pending task (for which the user/s is/are assignee/s)?

Could anyone tell me please where can I take a look in Docs?

Thanks a lot,
Steve

Hi,

by default there is no notification. Being able to notify a user would require the engine to somehow know how to contact the user, for which it’s near impossible to provide a generic solution.

The basic notion with user tasks is that they are available through some interface where they can be completed. Often the available tasks are shown to the user by providing a list or showing the tasks that relate to some context they are already looking at.

However, it is quite easy to use Camunda’s extension capabilities to do this yourself. The idea would be to create a TaskListener that is set to the “assignment” event. Each time the task is assigned, the listener is invoked. From within the delegation code, you have access to information about the task (so, who was it assigned to, for instance) and you can then code a notification to the user. For example, you could use the assigned user id to lookup the user’s e-mail address and send a message to them or even more advanced stuff to notify a user live on screen.

4 Likes

Hello, steftriant
Please look at example on github:

In this example Java Class = org.camunda.bpm.quickstart.TaskAssignmentListener read Email from Assignee User profile and send notification by Email. So to test it under “demo”, you have to set right Email for user “demo”. For example, yours. This can be done by Admin portal.
You will receive the Email with URL for the task, but this URL is not correct now. Fix it for actual by yourself.

1 Like

Hi @volodya327,

Can I please ask you sth about your last reply ?

What do you mean when you say that the Email URL for the assigned task is not correct and that I have to fix it for actual ?

Thanks a lot,
Steve

Hi !

  1. When you assign task for user “demo”, this user will receive Email with notification. The Email address of “demo” application will get from this user profile. You can edit it by Camunda Admin portal.
  2. User “demo” will receive Email with direct URL for assigned task. You can change Email message and URL to your own in TaskAssignmentListener.java:
    …
    email.setFrom("noreply@camunda.org");
    email.setSubject("Task assigned: " + delegateTask.getName());
    email.setMsg(“Please complete: http://localhost:8080/camunda/app/tasklist/default/#/task/” + taskId);
1 Like

Hi @volodya327 and thanks for your immediate feedback :slightly_smiling_face:

I would like to ask 2 points if you know:

  1. In the Java class file (TaskAssignmentListener.java) do you know how must I configure that the email will be sent to multiple users instead of 1 ?
// Get User Profile from User Management
      IdentityService identityService = Context.getProcessEngineConfiguration().getIdentityService();
      User user = identityService.createUserQuery().userId(assignee).singleResult();

      if (user != null) {
        
        // Get Email Address from User Profile
        String recipient = user.getEmail();
        
        if (recipient != null && !recipient.isEmpty()) {

          Email email = new SimpleEmail();
          email.setCharset("utf-8");
          email.setHostName(HOST);
          email.setAuthentication(USER, PWD);

          try {
            email.setFrom("noreply@camunda.org");
            email.setSubject("Task assigned: " + delegateTask.getName());
            email.setMsg("Please complete: http://localhost:8080/camunda/app/tasklist/default/#/task/" + taskId);

            email.addTo(recipient);

            email.send();
            LOGGER.info("Task Assignment Email successfully sent to user '" + assignee + "' with address '" + recipient + "'.");            

          } catch (Exception e) {
            LOGGER.log(Level.WARNING, "Could not send email to assignee", e);
          }

        } else {
          LOGGER.warning("Not sending email to user " + assignee + "', user has no email address.");
        }

      } else {
        LOGGER.warning("Not sending email to user " + assignee + "', user is not enrolled with identity service.");
      }
  1. In the pom.xml file have I to add any new Maven Dependencies ?

Thank you in advance,
Steve

Hi, Steve
The idea of this example is to Automaticaly send Email notification to Assignee.
Just for test, you can try to change String “recipient” by the String of Emails list like:
"user1@corp.com; superUser2@corp.com; user3@corp.com"
But this is bad style - to hardcode variables like Emails as constants in code.
You can use Email Group and change the list of users on Email server. But this is also hardcoding.

Maybe you want just to send Email to somebody ?
Try to find info about using “mail-send” connector in this forum:


You can dynamically create input parameters for this connector by javascript (on Listeners Tab) or by DMN table and be happy:

Input parameter

from
fromAlias
to
cc
bcc
subject
text
html
fileNames

Hi @volodya327 and sorry for my delay,

Here you mean sth like this ?

"user1@corp.com; user2@corp.com; user3@corp.com" = user.getEmail () ;

But, the “user” on the right side of the line is correct in that case ?

Thanks a lot,
Steve

Hi, Steve
You can replace the source code:

by this one:

OR you can set the Email list directly in another place of source code:

instead of:

1 Like

So @volodya327 I will have to try 1 of these 2 options to test it for multiple mail recipients, thanks a lot for your hint :slightly_smiling_face:

I will let you know

Best,
Steve

Hi @volodya327,

Can I ask you sth please ?
In my process, there is a multi-instance task which must be completed by 3 users.
I have defined the “Assignee” field of this task in Modeler as an expression which takes a different value based on the user. Like the following:

${assignee.value()}

Do you know how must I define the variable “assignee” inside the snippet of the TaskAssignmentListener.java file ?
For example in the following line (and also anywhere I see the word “assignee”) :

String assignee = delegateTask.getAssignee();

how must I define the “assignee” ? Must I write the expression which I wrote in the “Assignee” field of the task in Modeler ? Or sth else ?

Thanks a lot in advance,
Steve

Hi, Steve
You try to begin discussion which is out of scope of this topic.
You can write me private message with your Email and I’ll try to help you.

1 Like

Hi @volodya327,

Yes, of course, thanks again for your interest :slightly_smiling_face:

Steve

Hi,
This an old topic but I’d like to share with you a small prototype that I built to have real time push notifications from workflow instance processes. It was built with the idea of connecting a web user interface to it via WebSockets. The general idea was to have system similar to what you have with social media platforms: when you log in, pending task notifications assigned to you are fetched and if new ones are created while you are still logged, they will be sent to you directly. You can marked them as read to not fetch them the next time you log in. Once they are completed by you or another user candidate, they are from your list.
The code is here https://github.com/paulbares/camunda-notification. Keep in mind this is a prototype :grinning:.
Paul

This looks really interesting Paul, thanks for sharing with us!