cancel
Showing results for 
Search instead for 
Did you mean: 

How to get complete variables of a complete task

smartxiaofish
Champ in-the-making
Champ in-the-making
hi, i'm trying to create a new task, with variables, and complete it with variables update,  and i can't get variables setted in complete call.

here is the sample code.
//1. create a taskTask task = taskSrv.newTask();task.setName("test execution");task.setOwner(user1.getId());task.setAssignee(user2.getId());taskSrv.saveTask(task);//2. set task variablesMap<String, Object> taskVariables = new HashMap<String, Object>();taskVariables.put("finishedAmount", 0);taskSrv.setVariables(task.getId(), taskVariables);//3. complete this task with a new variableMap<String, Object> finishVariables = new HashMap<String, Object>();finishVariables.put("finishedAmount", 40);taskSrv.complete(user2Tasks.get(0).getId(), finishVariables);//4. get completed variableList<HistoricVariableInstance> hisVarList = historyService.createHistoricVariableInstanceQuery().taskId(hisTaskList.get(0).getId()).list();System.out.println(hisVarList);  // here only get varibale finshedAmount = 0List<HistoricDetail> hisDetailList = historySrv.createHistoricDetailQuery().variableUpdates().taskId(hisTaskList.get(0).getId()).list();System.out.println(hisDetailList); // and I tried historicDetailQuery, there is no results.‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

how can i get the finishedAmount with value 40 setted in taskService.complete()?

thanks a lot.
3 REPLIES 3

jbarrez
Star Contributor
Star Contributor
It seems you have hit a bug in Activiti. I ported your test and fixed it on the current master branch: https://github.com/Activiti/Activiti/commit/2e9cfb7cf7cdfe832a1eab4f4afaab8f30644805

smartxiaofish
Champ in-the-making
Champ in-the-making
thank you for quick reply. 🙂

there is another small question. when i can't get complete variables, i tried setVariables before complete the task.
so, is there any difference between the two approachs?
<java>
Map<String, Object> finishVariables = new HashMap<String, Object>();
finishVariables.put("finishedAmount", 40);
taskSrv.complete(task.getId(), finishVariables);
</java>

<java>
Map<String, Object> finishVariables = new HashMap<String, Object>();
finishVariables.put("finishedAmount", 40);
taskSrv.setVariables(task.getId(), finishVariables);
taskSrv.complete(task.getId());
</java>

jbarrez
Star Contributor
Star Contributor
Not functionally.

Technically, the first one will be one database transaction, second one will be two database transactions.