Search code examples
bpmncamunda

how to get user who completed user task in camunda


I want to get username of user who completed a user task in a camunda process.

for example consider a BMPN with only 2 steps , first is a user task and second is a externalTask. for a invocation of this BPMN if a user completes first user task then i should be able get its username in second externalTask.

I did not find any process variable being set in camunda after user task is complete.


Solution

  • The user who completed a user task in Camunda can be stored using a Task Listener. To set this up:

    1. Select the user task where you wish to record the data

    2. In the properties panel go to the 'Listeners' tab and click + in the 'Task Listener' section

    3. Set the 'Event Type' to 'complete'

    4. Set the 'Listener Type' to 'Expression'

    5. Enter the expression:

       ${task.execution.setVariable('taskCompletedBy', task.assignee)}
      

    When the user task is completed the task listeners expression will be executed. The expression takes the username from task.assignee, then uses the setVariable() function on the execution scope task.execution to store it in a variable. As the variable is stored on the execution scope it's available to the rest of the process. You can then use the variable as with any other variables in later user / service tasks.