is it possible to get the workflow version on which the process instance id is running on using java api ?
@Anirudh, When query for process instance it returns ProcessInstance as response and it has attribute called processDefinitionId which is a combination of processDefinitionKey:version:uniqueIdentifier
. So if you split by delimiter “:” can access the version (approach1) otherwise, you can query for processdefinitions with processdefinitionid to retrieve version (approach2).
Code to retrieve version from process instance (approach1):
Optional<ProcessInstance> processInstance = Optional.ofNullable(execution.getProcessEngineServices().getRuntimeService().createProcessInstanceQuery().active()
.processInstanceId("processInstanceId").singleResult());
if(processInstance.isPresent()){
String[] keys = processInstance.get().getProcessDefinitionId().split(":");
String version = keys[1];
}
Below is the code, how camunda generates the processDefinitionId:
Hi @Anirudh and @aravindhrs,
the proposal is fine for process models with a short name.
A safer implementation is to query for the process definition with:
ProcessDefinition processDefinition = repositoryService()
.createProcessDefinitionQuery()
.processDefinitionId(processInstance.getProcessDefinitionId())
.singleResult();
processDefinition.getVersion()
Hope this helps, Ingo
@Ingo_Richtsmeier, yes correct. Same thing i was mentioned in the approach2, to query for processdefinition to find the version