Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Activiti, how do I check if a variable is set?

For example I have a workflow which can start immediately or with a delay (startTime variable).

Right after the startEvent I have an exclusiveGateway where I check if the flow should go on or wait until startTime.

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

Starting the workflow passing a variable startTime works fine, but passing no startTime throws an exception:

Cannot resolve identifier 'startTime'

What would be the best way to check if startTime is set, since startTime != null is not working? I would prefer not to pass a startTime at all (not startTime=null).

Code that I use including the variable:

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

or without:

ProcessInstance instance = runtimeService.startProcessInstanceByKey(processKey, variables);
like image 293
flavio.donze Avatar asked May 31 '16 13:05

flavio.donze


2 Answers

Use the following expression:

${execution.getVariable('startTime') != null}
like image 95
Martin Avatar answered Sep 28 '22 02:09

Martin


You have to set startTime variable in both cases;

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

and

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

Then check variable in gateway

<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

You can use http://www.activiti.org/userguide/#bpmnTimerStartEvent

like image 27
fersmi Avatar answered Sep 28 '22 02:09

fersmi