I have implemented an Execution Listener so that I can get all (start,end,take) events for process instances related to activities such as StartEvent, EndEvent, Task, SubProcess, etc. When I receive Task events I would like to be able to correlate to corresponding SubProcess (id, name), if the Task is part of SubProcess. In some cases, there the task may not have any SubProcess associated. Problem is that when I receive Task event I can’t tell if it’s part of the SubProcess or not. Is there way to get information about SubProcess for a Task event using DelegateExecution object?
public ExecutionListener getExecutionListener() {
return new ExecutionListener() {
public void notify(DelegateExecution execution) throws Exception {
if (execution.getBpmnModelElementInstance() instanceof Task) {
//How to check task if part of subprocess. If so, get subprocess details (e.g. id, name)
}
}
};
}
At first I thought you were talking about a call activity when in fact you were talking about an embedded subprocess …my bad.
Give the following a try execution.getBpmnModelElementInstance().getParentElement(). If you are within an embedded subprocess you should get the following org.camunda.bpm.model.bpmn.impl.instance.SubProcessImpl@223e4842, otherwise if you are outside you will get something like org.camunda.bpm.model.bpmn.impl.instance.ProcessImpl@20983f35.
You could also get the id of the subprocess by doing something like this execution.getBpmnModelElementInstance().getParentElement().getAttributeValue(“id”) or name as well.