Activiti BPM gets variables in a task

You can get all the process or task variables using the TaskService:

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

I know that it is possible to get variables through processEngine.getTaskService().getVariable()

or

processEngine.getRuntimeService().getVariable()

but each operation above refers to a database. If I have a list of 100 tasks, I will make 100 database queries. I do not want to use this approach. Is there any other way to get a task or process related variables?

+4
source share
3 answers

Unfortunately, there is no way to do this through the "official" request API! However, what you can do is write a custom MyBatis request, as described here:

https://app.camunda.com/confluence/display/foxUserGuide/Performance+Tuning+with+custom+Queries (Note: Everything described in this article also works for Activiti naked, you don’t need the fox engine for this! )

Thus, you can write a query that selects tasks along with variables in one step. At my company, we used this solution because we had the same performance problem.

The disadvantage of this solution is the need to save user queries. For example, if you are updating Activiti, you need to make sure that your user request is still suitable for the database schema (for example, using integration tests).

+5
source

If the API API cannot be used, as elsvene says, you can query yourself for a database. There are several tables in the Activiti database.

You have act_ru_variable whether the currently running processes have stored variables. For an already completed procession, you have act_hi_procvariable . You can probably find a detailed explanation of what is on each table in the activiti userguide.

So you just need to make requests like

 SELECT * FROM act_ru_variable WHERE *Something* 
+1
source

The following test sends a value object (Person) to a process that simply adds some tracking data for demonstration.

I had the same problem to get a value object after executing the service in order to do some validation in my test.

The following code snippet shows the execution and collection of a varaible task after completion of execution.

 @Test public void justATest() { Map<String, Object> inVariables = new HashMap<String, Object>(); Person person = new Person(); person.setName("Jens"); inVariables.put("person", person); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("event01", inVariables); String processDefinitionId = processInstance.getProcessDefinitionId(); String id = processInstance.getId(); System.out.println("id " + id + " " + processDefinitionId); List<HistoricVariableInstance> outVariables = historyService.createHistoricVariableInstanceQuery().processInstanceId(id).list(); for (HistoricVariableInstance historicVariableInstance : outVariables) { String variableName = historicVariableInstance.getVariableName(); System.out.println(variableName); Person person1 = (Person) historicVariableInstance.getValue(); System.out.println(person1.toString()); } } 
0
source

All Articles