cancel
Showing results for 
Search instead for 
Did you mean: 

How to get process definition id in service task?

kesavkolla
Champ in-the-making
Champ in-the-making
I've a service task which implements JavaDelegate.  I want to get the current running process definition id.  Is there any API which returns the current process definition id?

I'm trying

runtimeService.createProcessInstanceQuery()
               .processInstanceId(executionContext.getProcessInstanceId()).singleResult().getProcessDefinitionId();

and is failing with NPE.  This is very first task in my process.
5 REPLIES 5

kesavkolla
Champ in-the-making
Champ in-the-making
I found the answer what I was looking.  I'm using Context to retrieve that information.


Context.getExecutionContext().getProcessDefinition().getId()

ssrajesh74
Champ in-the-making
Champ in-the-making
List <ProcessDefinition> ls = processEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKeyLike("testprocess").latestVersion().list();
   String processDefinitionId = ls.get(0).getId();

Regards,
Rajesh

mindaugas
Champ in-the-making
Champ in-the-making
Hello,

I have very similar situation:


        for (ProcessInstance prins : mainProceList) {
            if (prins != null && prins instanceof ExecutionEntity ){
              ProcessDefinitionImpl def = ((ExecutionEntity) prins).getProcessDefinition(); //…..

           }


one .getProcessDefinition() I get NPE:

java.lang.NullPointerException
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.ensureProcessDefinitionInitialized(ExecutionEntity.java:662)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.getProcessDefinition(ExecutionEntity.java:647)
…..

If I have current ProcessInstence how to get process definition? It's possible get proce.definition avoiding repositoryService nad additional querying?


Regards,
Mindaugas

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
From within a servicetask?

mindaugas
Champ in-the-making
Champ in-the-making
No, not in service task Delegate implementation.