Unable to call 'execution' in Javascript from Task Listener

When you try and run a Task Listener on a User Task for the Type: Complete, if you use JavaScript and try to reference execution, you get the following:

There was an exception while invoking the TaskListener. Message: 'Unable to evaluate script: ReferenceError: "execution" is not defined in at line number 1'

sample BPMN file:
TaskListnerTest.bpmn (3.2 KB)


Hi Stephen,

Using task listener you can reference execution currently at the task as follow


Using execution listener you can reference execution as follow


1 Like

@hassang, you know where task.execution is documented?

Best i can find is that the variable task is available when using Task Listeners, but cannot find any reference to execution being part of task.

Hi Stephen,

try this https://docs.camunda.org/javadoc/camunda-bpm-platform/7.5/org/camunda/bpm/engine/delegate/DelegateTask.html#getExecution()

Cheers, Ingo

@Ingo_Richtsmeier Do you know why execution is inside of the Task variable? Just looking to understand the architecture / design.

Hi Stephen,

Based on TaskListener documentation below


org.camunda.bpm.engine.impl.pvm.delegate.TaskListener interface must be implemented where there is only one method called “notify” with an instance of DelegateTask is available

I assumed Java & script behavior are equivalent (instance of DelegateTask —> task)

Script task listener examples show the availability of task instance (see below)

<userTask id="task">
    <camunda:taskListener event="create">
      <camunda:script scriptFormat="groovy">
        println task.eventName

& based on https://docs.camunda.org/javadoc/camunda-bpm-platform/7.5/org/camunda/bpm/engine/delegate/DelegateTask.html
You can get execution from DelegateTask object


In addition to Hassan’s answer, the section on task listeners as scripts confirms that task is an instance of DelegateTask.


1 Like

Thanks. Appreciate the details :slight_smile: