是否可以在 camunda 定义 xml 中为用户任务设置变量?
我想设置一个变量(可删除),它会因任务而异。
任务 1 实例:deletable = true
任务 2 实例:deletable = true
任务 3 实例:deletable = false
任务 4 实例:deletable = false
这是实际的任务配置:
<bpmn2:userTask id="createtrunkdoc" camunda:candidateUsers="${candidateUser}" camunda:candidateGroups="provisioning" camunda:assignee="${candidateUser}" name="Create New
Trunk Request">
<bpmn2:incoming>SequenceFlow_1</bpmn2:incoming>
<bpmn2:outgoing>SequenceFlow_3</bpmn2:outgoing>
</bpmn2:userTask>
测试用例(camunda:7.1.0-Final)
@RunWith(MockitoJUnitRunner.class)
public class testTest {
@Rule
public ProcessEngineRule processEngineRule = new ProcessEngineRule();
@Test
@Deployment(resources = { "test.bpmn20.xml" })
public void testHappyPath() {
ProcessInstance processInstance = runtimeService().startProcessInstanceByKey("nipa-createsipinterconnect");
assertThat(processInstance).isStarted().isNotEnded().task().hasDefinitionKey("reviewnewtrunk");
Task task = taskService().createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertEquals(true, taskService().getVariable(task.getId(), "deletable"));
}
}
完整的 XML:
<?xml version="1.0" encoding="UTF-8"?>
<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:camunda="http://activiti.org/bpmn" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd" id="_1RW-0F22EeOq-_ehbw1S0Q" exporter="camunda modeler" exporterVersion="2.5.0" targetNamespace="http://activiti.org/bpmn">
<bpmn2:collaboration id="_Collaboration_8">
<bpmn2:participant id="nipacreatesipinterconnect" name="Create new SIP Interconnect" processRef="nipa-createsipinterconnect"/>
</bpmn2:collaboration>
<bpmn2:process id="nipa-createsipinterconnect" name="Create new SIP Interconnect" isExecutable="true">
<bpmn2:laneSet id="LaneSet_1" name="Lane Set 1">
<bpmn2:lane id="Lane_1" name="Lane 1">
<bpmn2:flowNodeRef>reviewnewtrunk</bpmn2:flowNodeRef>
<bpmn2:flowNodeRef>StartCreateSIPInterconnect</bpmn2:flowNodeRef>
</bpmn2:lane>
</bpmn2:laneSet>
<bpmn2:userTask id="reviewnewtrunk" camunda:candidateGroups="management" camunda:candidateUsers="" name="Review New 
Trunk Request">
<bpmn2:extensionElements>
<camunda:inputOutput>
<camunda:inputParameter name="deletable">${true}</camunda:inputParameter>
</camunda:inputOutput>
</bpmn2:extensionElements>
<bpmn2:incoming>SequenceFlow_5</bpmn2:incoming>
</bpmn2:userTask>
<bpmn2:startEvent id="StartCreateSIPInterconnect" name="Describe New 
SIP Interconnect 
Request">
<bpmn2:outgoing>SequenceFlow_5</bpmn2:outgoing>
</bpmn2:startEvent>
<bpmn2:sequenceFlow id="SequenceFlow_5" name="" sourceRef="StartCreateSIPInterconnect" targetRef="reviewnewtrunk"/>
</bpmn2:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="_Collaboration_8">
<bpmndi:BPMNShape id="_BPMNShape_Participant_12" bpmnElement="nipacreatesipinterconnect" isHorizontal="true">
<dc:Bounds height="333.0" width="1381.0" x="48.0" y="16.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_9" bpmnElement="StartCreateSIPInterconnect">
<dc:Bounds height="36.0" width="36.0" x="228.0" y="154.0"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="54.0" width="116.0" x="188.0" y="195.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_UserTask_22" bpmnElement="reviewnewtrunk">
<dc:Bounds height="80.0" width="157.0" x="516.0" y="132.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_Lane_7" bpmnElement="Lane_1" isHorizontal="true">
<dc:Bounds height="333.0" width="1351.0" x="78.0" y="16.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_5" bpmnElement="SequenceFlow_5" sourceElement="_BPMNShape_StartEvent_9" targetElement="_BPMNShape_UserTask_22">
<di:waypoint xsi:type="dc:Point" x="264.0" y="172.0"/>
<di:waypoint xsi:type="dc:Point" x="516.0" y="172.0"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="6.0" width="6.0" x="291.0" y="172.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn2:definitions>