fml2
March 12, 2020, 8:17am
1
Hello,
within the body of a JavaDelegate, I’d like to get the process key (in the modeler, the attribute is called “id”) of the process model currently being executed. I’ve come up with this:
execution.getProcessEngineServices().getRepositoryService().createProcessDefinitionQuery()
.processDefinitionId(execution.getProcessDefinitionId()).singleResult().getKey());
Is there a more elegant and shorter solution?
Thank you for any hints.
1 Like
Hello
You can access DOM.
execution.getBpmnModelInstance().getDocument().getElementsByNameNs("http://www.omg.org/spec/BPMN/20100524/MODEL", "process").get(0).getAttribute("id")
or
execution.getBpmnModelInstance().getModelElementsByType(org.camunda.bpm.model.bpmn.instance.Process.class).iterator().next().getId()
best regards
R.
fml2
March 12, 2020, 9:54am
4
Thank you for the idea. Frankly said, I’d prefer to stay within the pure Java API and not resort to XML parsing (or having to know how the model is represented internally).
1 Like
@fml2 processdefinitionkey can be directly accessed from DelegateExecution instance of the Java Delegate like below snippet:
It will return the process definition key for the process instance this execution is associated with.
public class LoggerDelegate implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) throws Exception {
String processDefinitionId = execution.getProcessDefinitionId();
}
}
I think it would returns an compexID (modelProcessDefinitionId:Version:DeplyomentID) like this
orderprocess:11:5137
Hi @fml2 and others,
this is shorter, but uses internal API (which may change in the future):
ExecutionEntity executionEntity = (ExecutionEntity) execution;
executionEntity.getProcessDefinition().getKey();
Hope this helps, Ingo
1 Like
fml2
March 12, 2020, 12:59pm
9
For me, it gives a string that looks like a UUID. Not “ProcessKey:Version:DeploymentID”.