Get process instance business key from Delegate Task

I am trying to retrieve business key for a process instance of a task through task listeners. The event type of my listener is create. Below is my implementation of task listener:

public void notify(DelegateTask delegateTask) {; // Prints correct ID
    ProcessInstance instance =
            .singleResult(); // instance is null"Business key: {}", instance.getBusinessKey()); // NPE occurs here

But I keep getting NPE in above code. Are create listeners executed before the creation of process instance?

Hi @shan-96,


will do the trick.

Hope this helps, Ingo


Wow thanks @Ingo_Richtsmeier ! Getting the business key was much easier than I thought. This works.

Hi @shan-96 , you can try like this also:

1 Like

Thanks @aravindhrs and @Ingo_Richtsmeier. Is it guaranteed though that results from both APIs will be consistent?

Hi @shan-96,

they are: camunda-bpm-platform/ at master · camunda/camunda-bpm-platform · GitHub

Hope this helps, Ingo

1 Like