cancel
Showing results for 
Search instead for 
Did you mean: 

Get Process Name in Java service

eramesh
Champ on-the-rise
Champ on-the-rise
Hi,

We are using Enterprise Activiti 1.5

I'm trying to get the Process Name of the current process in Java service task but couldn't find any method, see method to get the process instance id by "execution.getProcessInstanceId()".

Any idea? Please let me know.

Thanks!!
5 REPLIES 5

cjose
Elite Collaborator
Elite Collaborator

Hi,

You can get it via process instance query API 

execution.getEngineServices().getRuntimeService().createProcessInstanceQuery().processInstanceId(execution.getProcessInstanceId()).singleResult().getName();

eramesh
Champ on-the-rise
Champ on-the-rise

Thanks for the reply Ciju!

Tried the code it gave me null pointer exception so tried to get the query count for the process instance

ProcessInstanceQuery pqry = execution.getEngineServices().getRuntimeService().createProcessInstanceQuery().processInstanceId(execution.getProcessInstanceId())

and the query count is 0.

We are using Enterprise Activiti 1.5

Regards,

Durai

cjose
Elite Collaborator
Elite Collaborator

Hi Ramesh,

That is probably because the process instance is not yet committed into the database at the time of your query.

For example if you do query count in a script/service task in a process that looks like Start->Script->End it doesn't work.

Now if you make the script/service task "Async" and do the process instance query, it works.

Regards,

Ciju

eramesh
Champ on-the-rise
Champ on-the-rise

Hi Ciju,

Yes I had the query count logic in "Execution Listeners" start event in the task following Process Start. After marking the checkbox "Asyncronous" checked in the task where my script exists then I was able to get the query result.

When you got minute can you please throw some light on the purpose of the "Asynchronous" checkbox in the user task does.

Thank you very much for the help!!

Regards,

Ramesh

cjose
Elite Collaborator
Elite Collaborator

Hi Ramesh,

Upon starting a process, activiti persists the data to database upon reaching the first asynchronous task. Hence the query was able to fetch from the name from the database!

It is explained here in detail Activiti User Guide ( section Asynchronous Continuations)

Regards,

Ciju