User task listeners: create and assignment plus assignee? bug or feature?

Greeting!

Is it a bug or a feature? if two listeners on user task are defined, create and assignment listeners. Also having assignee set at once. Create listener kicks second after assignment listener.

Logically i would assume that create listener should have been kicked first no matter what. Also Task Lifecycle starts with create.

dummyUserTask.bpmn (3.3 KB)

Output is:
Hello I am ASSIGNMENT listener
hello Im CREATE listener

what do you think?

thanks in advanced!

Hi @Tigly_Migly

assignment: occurs when the task is assigned to somebody. Note: when process execution arrives in a userTask, an assignment event will be fired first, before the create event is fired. This might seem like an unnatural order but the reason is pragmatic: when receiving the create event, we usually want to inspect all properties of the task, including the assignee.

See below link
https://docs.camunda.org/manual/7.7/user-guide/process-engine/delegation-code/#task-listener

2 Likes

Hassang thanks a bunch!
totally missed that part in the docs.

Reasonable explanation and, yes, it is very much unnatural order :slight_smile: .

lets say on task assignment, email should be send. So lets place assignment listener who will take care of that. Assume, task creation listener has terrific logic,as well (for example fill in task description and local task attributes) - and, (thing happens), it’s failed. Now we have - email which is send to a user, kindly telling him/her about the task assigned, but task is not assigned, even more, task is not created.

Just wandering would it be more pragmatically (and logically) on task creation to check incoming assignee attribute (which i assume is known at this point) and based on that, after task is created, kick in task assignment … ?

3 Likes

@hassang Is this still valid? I notice in the latest documentation, ‘create’ event will indeed fire before everything else as it should (as of May 2020, Camunda BPM 7.12/13).

The create event fires when the task has been created and all task properties are set. No other task-related event will be fired before the create event.

Reference: Delegation Code | docs.camunda.org

In that case, this thread of should updated with proper remarks with versions and closed for further comments.

Thanks and Regards
Chaitanya

1 Like

Hi @chaitanyajoshi,

Thank you so much for sharing…
You are completely right.
My above post is no longer valid.