[ External task ] Acees to current process execution

Hello,

When i’m in External Task, could i acces to the process cycle, exemple i want to obtain the current process instance and create an incident.

   client.subscribe("myExtTsk")
            .lockDuration(1000)
            .handler((externalTask, externalTaskService) -> {
                System.out.println("The External Task is started ");
                try {
                    // if no problem i complete task  
                    externalTaskService.complete(externalTask);
                }catch(Exception e){
                   // if there is problem i want to create an incident and throw error
                   /*
                  THIS IS WHAT I WANT TO DO BUT COULD NOT    : 
                  externalTask.getProcessInstance().createIncident("10","a problem is occured"); 

                 */
                    throw  new BpmnError("Problem while executing service");
                }
                System.out.println("The External Task is completed");
            }).open();

Thanks

Samir

Hi @slb,

in an external task wroker you have to write

externalTaskService.handleFailure(externalTask, "my error message", "my stacktrace", 0, 0);

to create an incident in the cockpit.

See https://github.com/camunda/camunda-external-task-client-java/blob/master/client/src/main/java/org/camunda/bpm/client/task/ExternalTaskService.java#L107-L127 for the complete API documentation.

Hope this helps, Ingo

Hi,
Thanks [Ingo_Richtsmeier],
This should response to my question.