AnsweredAssumed Answered

How can we return an functional error in activiti 7

Question asked by parul.b.aggarwal on Feb 28, 2019

We have a usecase where we need to perform some business validations when a process is started and return an error code with synchronous response in case the business validation fails. Is there any way we can do that in activiti 7. Below is an example of validating the input parameters inside the XML which should return an error code in case validation fails.

 

We have tried the acitivit 6 way but the tags are not working.  No error code is thrown in case we execute the XML. We have also tried to add boundaryEvent and attach it to the validateInputImpl still it does not throw any exception.

 

Any help will be appreciated. Thanks in advance.

 

XML:- 

<bpmn2:error id="myError" errorCode="WOM_03.203.003" />


  <bpmn2:process id="process-097cd6ce-71d9-4db5-9e4b-4f50757292bf_1" name="createWorkOrder" isExecutable="true">
    <bpmn2:documentation />
    <bpmn2:startEvent id="StartEvent_1">
      <bpmn2:outgoing>SequenceFlow_1717b9t</bpmn2:outgoing>
    </bpmn2:startEvent>
    <bpmn2:serviceTask id="ServiceTask_1aflbq5" name="Validate Input" implementation="validateInputImpl">
      <bpmn2:incoming>SequenceFlow_1717b9t</bpmn2:incoming>
      <bpmn2:outgoing>SequenceFlow_0shefwo</bpmn2:outgoing>
    </bpmn2:serviceTask>
    <bpmn2:exclusiveGateway id="ExclusiveGateway_0oag0b8" name="Validation Passed">
      <bpmn2:incoming>SequenceFlow_0shefwo</bpmn2:incoming>
      <bpmn2:outgoing>SequenceFlow_014el6n</bpmn2:outgoing>
      <bpmn2:outgoing>SequenceFlow_11nngp3</bpmn2:outgoing>
    </bpmn2:exclusiveGateway>
    <bpmn2:sequenceFlow id="SequenceFlow_0shefwo" sourceRef="ServiceTask_1aflbq5" targetRef="ExclusiveGateway_0oag0b8" />
    <bpmn2:endEvent id="EndEvent_0l0ebwj" name="END - Security Exception">
 
 <bpmn2: errorEventDefinition errorRef="myError" />
      <bpmn2:incoming>SequenceFlow_014el6n</bpmn2:incoming>
      <bpmn2:incoming>SequenceFlow_0odgyv0</bpmn2:incoming>
    </bpmn2:endEvent>
    <bpmn2:sequenceFlow id="SequenceFlow_014el6n" name="No" sourceRef="ExclusiveGateway_0oag0b8" targetRef="EndEvent_0l0ebwj">
      <bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression">${wocontainsofferings==false}</bpmn2:conditionExpression>
    </bpmn2:sequenceFlow>
 
  </bpmn2:process>

 

ProcessStartController:-

 

ProcessInstance processInstance = processRuntime
    .start(ProcessPayloadBuilder.start().withProcessDefinitionKey(processDefinitionKey)
      .withProcessInstanceName("Create Entity Process: " + new Date())
      .withVariable("entity",objectToBeValidated).build());

Outcomes