Activiti BPM get Variables within Task

Timofei picture Timofei · Dec 14, 2012 · Viewed 7.2k times · Source

is it possible to get all process or task variables using TaskService:

processEngine.getTaskService.createTaskQuery().list();

I know there is an opportunity to get variables via processEngine.getTaskService().getVariable()

or

processEngine.getRuntimeService().getVariable()

but every of operation above goes to database. If I have list of 100 tasks I'll make 100 queries to DB. I don't want to use this approach. Is there any other way to get task or process related variables?

Answer

elsvene picture elsvene · Dec 17, 2012

Unfortunately, there is no way to do that via the "official" query API! However, what you could do is writing a custom MyBatis query as described here:

https://app.camunda.com/confluence/display/foxUserGuide/Performance+Tuning+with+custom+Queries (Note: Everything described in the article also works for bare Activiti, you do not need the fox engine for that!)

This way you could write a query which selects tasks along with the variables in one step. At my company we used this solution as we had the exact same performance problem.

A drawback of this solution is that custom queries need to be maintained. For instance, if you upgrade your Activiti version, you will need to ensure that your custom query still fits the database schema (e.g., via integration tests).