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)

2 Likes

Hi Stephen,

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

task.execution

Using execution listener you can reference execution as follow

execution

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.
Thanks!

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

https://docs.camunda.org/manual/7.3/guides/user-guide/#process-engine-delegation-code-task-listener

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">
  <extensionElements>
    <camunda:taskListener event="create">
      <camunda:script scriptFormat="groovy">
        println task.eventName
      </camunda:script>
    </camunda:taskListener>
  </extensionElements>
</userTask>

& 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

2 Likes

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

Cheers,
Thorben

1 Like

Thanks. Appreciate the details :slight_smile: