6

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);
flavio.donze
  • 7,432
  • 9
  • 58
  • 91
  • 1
    Instead of not setting `startTime` at all, you could set it to a special value, for example `NONE`, and then check in the process if it's set to `NONE` to decide what to do. – Jesper May 31 '16 at 14:15

2 Answers2

16

Use the following expression:

${execution.getVariable('startTime') != null}
Martin
  • 176
  • 1
  • 2
2

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

fersmi
  • 601
  • 3
  • 9
  • Yes I know that I can set the variable to `null`. I would prefer to have a method where I do not have to set the variable. For example I have two GUIs and each of them fills in only the variables it provides, meaning that in GUI1 are different variables than in GUI2. I upvoted, but can't mark it as answer. – flavio.donze Jun 01 '16 at 13:30
  • You can add ServiceTask before Gateway, which check if variable is set and if not, then set it with null. – fersmi Jun 02 '16 at 06:00