05-29-2015 08:22 AM
processEngine.getTaskService().setVariable(taskId, "var_save", "this is a save var");
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<process id="simple_process" name="Simple Process" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<userTask id="usertask1" name="User Task"></userTask>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow2" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_simple_process">
<bpmndi:BPMNPlane bpmnElement="simple_process" id="BPMNPlane_simple_process">
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="90.0" y="90.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="55.0" width="105.0" x="170.0" y="80.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="320.0" y="90.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="125.0" y="107.0"></omgdi:waypoint>
<omgdi:waypoint x="170.0" y="107.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="275.0" y="107.0"></omgdi:waypoint>
<omgdi:waypoint x="320.0" y="107.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
// Deploy and start process
…
// #####################
TaskService taskService = processEngine.getTaskService();
Task task = taskService.createTaskQuery().singleResult();
// Unassigned task list
List<Task> taskList = taskService.createTaskQuery().taskUnassigned().list();
String taskId = taskList.get(0).getId(); // only one task
// Assignee: 'kermit'
taskService.setAssignee(taskId, "kermit");
// Save var without complete
taskService.setVariable(taskId, "var_save", "this is a save var");
// Complete task with other var
Map<String, Object> variableMapComplete = new HashMap<String, Object>();
variableMapComplete.put("var_complete", "this is a complete var");
taskService.complete(taskList.get(0).getId(), variableMapComplete);
// print historic vars from all activities
HistoryService historyService = processEngine.getHistoryService();
List<HistoricActivityInstance> processInstanceTaskList = historyService.createHistoricActivityInstanceQuery()
.processInstanceId(processInstance.getId())
.orderByHistoricActivityInstanceStartTime().desc()
.orderByHistoricActivityInstanceEndTime().desc().list();
for (HistoricActivityInstance hcoActivityInstance : processInstanceTaskList) {
System.out.println("Activity: " + hcoActivityInstance.getActivityName());
List<HistoricDetail> historicVariableUpdateList = historyService.createHistoricDetailQuery()
.variableUpdates()
.activityInstanceId(hcoActivityInstance.getId())
.orderByTime().desc().list();
for (HistoricDetail historicDetail : historicVariableUpdateList) {
HistoricVariableUpdate hcoVar = (HistoricVariableUpdate) historicDetail;
System.out.println("\tVariable –> " + hcoVar.getVariableName() + ": " + hcoVar.getValue());
}
}
Activity: End
Activity: User Task
Variable –> var_complete: this is a complete var
Variable –> var_save: this is a save var
Activity: Start
Activity: End
Activity: User Task
Variable –> var_complete: this is a complete var
Activity: Start
06-03-2015 04:08 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.