Get DelegateExecution from RuntimeService

Hi,

I have a piece of Java code where I have the RuntimeService
(RuntimeService runtimeService = ProcessEngines.getDefaultProcessEngine().getRuntimeService();)
a process_instance_id and a task_instance_id (e.g. from a UserTask).

Is there a way I can get/access the DelegateExecution of that Task (so I can call a class from there)?
(Having an Execution Listener doesn’t help me because I don’t want this code to be executed either at start or end of the task, but at any point).

Thanks!

Hi @kontrag,

What is the goal you are trying to achieve in terms of functionality?

Cheers,
Thorben

Hi @thorben,

I have a Java class that handles the receiving of websocket messages.
In that messages I have information like “process_instance_id”, “task_instance_id” and in that class I can access the RuntimeService (and subsequently the Execution).
From that class, once I receive a message I want to trigger an event on a task (e.g. UserTask). So I want to access the DelegateExecution to invoice some TaskListeners/ExecutionListeners.

Hope that helps.

Thanks!

From BPMN Error event on User Task - How to correlate to the current instance - #3 by kontrag I understand that you would like to throw a BPMN error from such a listener. @StephenOTT’s idea in this thread is as follows:

  1. Your websocket handler class detects an error condition
  2. Your class completes the task via TaskService#completeTask providing a process variable raiseError
  3. You have an execution listener on the activity’s end event that throws BpmnError whenever it sees the raiseError variable
  4. The process engine triggers the error boundary event

That way, the process engine calls the execution listener triggered via task completion. There is no way to tell the process engine to invoke a listener outside of process instance execution context, so what you ask for in the original post is not possible.

All that said, I believe the proposed solution does not work due to the following missing feature: https://app.camunda.com/jira/browse/CAM-5399. You could work around that by introducing a script or service task after the user task and throwing and catching the BpmnError there as follows:

Of course this means you will have to change your process model because of this rather technical concern.

Cheers,
Thorben

1 Like

Thanks @thorben,

I would like to avoid your idea, which can be similarly be implemented with a X-OR gateway after the user task.
But I have to find a workaround indeed.
I’m thinking of trying to have a call activity which will call the User Task and then attach the ErrorEvent on the Call activity once the called User Task is completed. But I have some issues to pass a variable from the inner called process to the parent Call activity.

Of what nature are those issues? Have a look at the call activity documentation for what you can do.

Well, I think I figured out how are the variables passed.
But the issue is the following:
In the called subprocess I update a process variable to catch the error later and I complete the User Task with the REST API. The process variable is checked in the Execution Listener (defined as “end event”) in the parent Call Activity.
However the ExecutionListener is executed before the inner called subprocess is actually completed.
How is that possible? I thought the ExecutionListener will be executed after the inner has been completed.
Or is it executed everytime I interact with the execution?