2016-05-31 94 views
3

例如,我有一个工作流程,可以立即开始或延迟(startTime变量)。在Activiti中,如何检查变量是否已设置?

紧接在startEvent之后,我有一个exclusiveGateway,我检查流量是否应该继续或等到startTime

<exclusiveGateway id="startGateway" default="startSequenceFlow3"/> 
<sequenceFlow id="startSequenceFlow1" sourceRef="startGateway" targetRef="startTimer"> 
    <conditionExpression xsi:type="tFormalExpression"><![CDATA[${startTime != null}]]></conditionExpression> 
</sequenceFlow> 

启动工作流传递变量startTime工作正常,但传球没有startTime抛出一个异常:

无法解析标识“开始时间”

什么将是最好的方式检查startTime是否设置,因为startTime != null不工作?我不想通过startTime(不是startTime=null)。

variables.put("startTime", startTime); 
ProcessInstance instance = runtimeService.startProcessInstanceByKey(processKey, variables); 

或不:我使用包括可变

代码

ProcessInstance instance = runtimeService.startProcessInstanceByKey(processKey, variables); 
+1

而不是不设置'startTime'可言,你可以将其设置为特殊值,例如'NONE',然后在这个过程中检查它是否被设置为'NONE'决定要做什么。 – Jesper

回答

5

使用下面的表达式:

${execution.getVariable('startTime') != null} 
+0

IMO这是最好的答案。 –

3

你必须设置开始时间变量在这两种情况下,

variables.put("startTime", startTime); 
ProcessInstance instance = runtimeService.startProcessInstanceByKey(processKey, variables); 

variables.put("startTime", null); 
ProcessInstance instance = runtimeService.startProcessInstanceByKey(processKey, variables); 

然后检查变量在网关

<exclusiveGateway id="startGateway" default="waitSequenceFlow"/> 
<sequenceFlow id="startSequenceFlow" sourceRef="startGateway" targetRef="firstTask"> 
    <conditionExpression xsi:type="tFormalExpression"><![CDATA[${empty startTime}]]></conditionExpression> 
</sequenceFlow> 
<sequenceFlow id="waitSequenceFlow" sourceRef="startGateway" targetRef="startTimer"/> 

OR

您可以使用http://www.activiti.org/userguide/#bpmnTimerStartEvent

+0

是的我知道我可以将变量设置为null。我宁愿有一个方法,我不必设置变量。例如,我有两个GUI,每个GUI都只填写它提供的变量,这意味着在GUI1中的变量不同于GUI2中的变量。我upvoted,但不能标记为答案。 –

+0

您可以在Gateway之前添加ServiceTask,它检查变量是否设置,如果不是,则将其设置为null。 – fersmi