<?xml version="1.0" encoding="UTF-8"?>
<!-- Original howtoifs teaching template. Not imported or executed in IFS.
     Import as a template, inspect, then clone under a unique process key.
     Fictional input: ExternalReference (text). No API or REST tasks. -->
<bpmn:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL"
 xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
 xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"
 xmlns:di="http://www.omg.org/spec/DD/20100524/DI"
 xmlns:camunda="http://camunda.org/schema/1.0/bpmn"
 id="Definitions_DemoReference" targetNamespace="https://howtoifs.com/examples/workflows">
 <bpmn:process id="demoRequireReference" name="Demo: require a reference" isExecutable="false">
  <bpmn:startEvent id="Start" name="Reference received">
   <bpmn:outgoing>Flow_Start_Check</bpmn:outgoing>
  </bpmn:startEvent>
  <bpmn:scriptTask id="CheckReference" name="Check reference" scriptFormat="JavaScript">
   <bpmn:incoming>Flow_Start_Check</bpmn:incoming>
   <bpmn:outgoing>Flow_Check_Decision</bpmn:outgoing>
   <bpmn:script><![CDATA[var reference = execution.getVariable('ExternalReference');
var referenceMissing =
  reference == null || String(reference).trim().length === 0;
execution.setVariable('referenceMissing', referenceMissing);]]></bpmn:script>
  </bpmn:scriptTask>
  <bpmn:exclusiveGateway id="ReferenceMissing" name="Reference missing?" default="Flow_Success">
   <bpmn:incoming>Flow_Check_Decision</bpmn:incoming>
   <bpmn:outgoing>Flow_Failure</bpmn:outgoing>
   <bpmn:outgoing>Flow_Success</bpmn:outgoing>
  </bpmn:exclusiveGateway>
  <bpmn:endEvent id="MissingReference" name="Reference required">
   <bpmn:extensionElements>
    <camunda:inputOutput>
     <camunda:inputParameter name="ifsBpaValidationErrorMessages">
      <camunda:map>
       <camunda:entry key="en">Enter an external reference before continuing.</camunda:entry>
      </camunda:map>
     </camunda:inputParameter>
    </camunda:inputOutput>
    <camunda:executionListener event="end" class="com.ifsworld.fnd.bpa.process.validation.IfsBpaFailureEndEventListener" />
   </bpmn:extensionElements>
   <bpmn:incoming>Flow_Failure</bpmn:incoming>
   <bpmn:terminateEventDefinition id="Terminate_MissingReference" />
  </bpmn:endEvent>
  <bpmn:endEvent id="ReferenceAccepted" name="Reference accepted">
   <bpmn:incoming>Flow_Success</bpmn:incoming>
  </bpmn:endEvent>
  <bpmn:sequenceFlow id="Flow_Start_Check" sourceRef="Start" targetRef="CheckReference" />
  <bpmn:sequenceFlow id="Flow_Check_Decision" sourceRef="CheckReference" targetRef="ReferenceMissing" />
  <bpmn:sequenceFlow id="Flow_Failure" name="Missing" sourceRef="ReferenceMissing" targetRef="MissingReference">
   <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${referenceMissing == true}</bpmn:conditionExpression>
  </bpmn:sequenceFlow>
  <bpmn:sequenceFlow id="Flow_Success" name="Present (default)" sourceRef="ReferenceMissing" targetRef="ReferenceAccepted" />
 </bpmn:process>
 <bpmndi:BPMNDiagram id="Diagram_DemoReference">
  <bpmndi:BPMNPlane id="Plane_DemoReference" bpmnElement="demoRequireReference">
   <bpmndi:BPMNShape id="Shape_Start" bpmnElement="Start"><dc:Bounds x="90" y="142" width="36" height="36" /></bpmndi:BPMNShape>
   <bpmndi:BPMNShape id="Shape_Check" bpmnElement="CheckReference"><dc:Bounds x="180" y="120" width="100" height="80" /></bpmndi:BPMNShape>
   <bpmndi:BPMNShape id="Shape_Decision" bpmnElement="ReferenceMissing" isMarkerVisible="true"><dc:Bounds x="340" y="135" width="50" height="50" /></bpmndi:BPMNShape>
   <bpmndi:BPMNShape id="Shape_Failure" bpmnElement="MissingReference"><dc:Bounds x="472" y="52" width="36" height="36" /></bpmndi:BPMNShape>
   <bpmndi:BPMNShape id="Shape_Success" bpmnElement="ReferenceAccepted"><dc:Bounds x="472" y="232" width="36" height="36" /></bpmndi:BPMNShape>
   <bpmndi:BPMNEdge id="Edge_Start_Check" bpmnElement="Flow_Start_Check"><di:waypoint x="126" y="160" /><di:waypoint x="180" y="160" /></bpmndi:BPMNEdge>
   <bpmndi:BPMNEdge id="Edge_Check_Decision" bpmnElement="Flow_Check_Decision"><di:waypoint x="280" y="160" /><di:waypoint x="340" y="160" /></bpmndi:BPMNEdge>
   <bpmndi:BPMNEdge id="Edge_Failure" bpmnElement="Flow_Failure"><di:waypoint x="365" y="135" /><di:waypoint x="365" y="70" /><di:waypoint x="472" y="70" /></bpmndi:BPMNEdge>
   <bpmndi:BPMNEdge id="Edge_Success" bpmnElement="Flow_Success"><di:waypoint x="365" y="185" /><di:waypoint x="365" y="250" /><di:waypoint x="472" y="250" /></bpmndi:BPMNEdge>
  </bpmndi:BPMNPlane>
 </bpmndi:BPMNDiagram>
</bpmn:definitions>
