I have created a process which gets called as a REST call, which has multiple service-tasks i.e. the process looks something like this : -
Start —> [Service Task A] —> [Service Task B] —> [Service Task C] --> Stop
Each service-task performs some business logic and has got a try/catch block. I want to have a logic inside each service-task, so that the next service-task DOESN’T get executed, if there is an exception in that service-task and the process should stop and return. One way to do this is having an Exclusive -gateway between each service-task i.e. I can have a boolean (e.g. executeNextTask) in each service task and only if its value is true, then I should go to the next service-task , else stop. but is there any other better/easier way of achieving this.
Thanks
Vinay
tijs
May 4, 2017, 7:54pm
2
Hi Vinay,
You could add an embedded sub process and place the service tasks in this sub process. Then add a boundary error event to the embedded sub process listening to the error event that you are throwing from your service task.
Best regards,
Tijs
Thanks @tijs for answering this. Have a followup dumb question
I created a Process , which has one Sub-process which internally has Two Sub-tasks (Step1 and Step2). Step 1 throws an BpmnError
public class Step1 implements JavaDelegate{
@Override<img src="//cdck-file-uploads-canada1.s3.dualstack.ca-central-1.amazonaws.com/flex035/uploads/flowable/original/1X/badf3fb07e44e337794ade048dc5d47fbaf05810.png" width="690" height="224"><img src="//cdck-file-uploads-canada1.s3.dualstack.ca-central-1.amazonaws.com/flex035/uploads/flowable/original/1X/e6321a36be2f68b786924604ae421bbfe7d4d71a.png" width="690" height="367">
public void execute(DelegateExecution execution) {
System.out.println(" ************** Entering Step 1 ***********");
try{
throw new Exception ("Exception by Step1");
}catch(Exception ex){
System.out.println(" >>>>>>>>.. INSIDE EXCEPTION BLOCK <<<<<<<<<<<<<<<<<");
new BpmnError("Step1Failed",ex.getMessage());
}
}
}
My BPMN XML look like this :-
< process id=“subProcessTutorial” name=“Sub Process Tutorial” isExecutable=“true” >
< documentation >Sub Process Tutorial< /documentation >
< startEvent id=“startEvent1” >< /startEvent >
< sequenceFlow id=“sid-46C54F4A-87F7-48DC-906C-CA15DB1FFB8D” sourceRef=“startEvent1” targetRef=“sid-5CB9EA76-69A8-4E92-B97D-DA237F5852AE” >< /sequenceFlow >
< endEvent id=“sid-BE4B0F86-E103-476B-AE43-831B5E42DE81” >< /endEvent >
< sequenceFlow id=“sid-DBD4BA55-FF32-40B9-BEA2-4376461FDBDC” sourceRef=“sid-5CB9EA76-69A8-4E92-B97D-DA237F5852AE” targetRef=“sid-BE4B0F86-E103-476B-AE43-831B5E42DE81” >< /sequenceFlow >
< subProcess id=“sid-5CB9EA76-69A8-4E92-B97D-DA237F5852AE” name=“SubProcess01” >
< serviceTask id=“sid-219B212D-1E92-4AF9-8989-0CE7C2C441F1” name=“Step 1” flowable:class=“com.amex.imdp.Step1” >< /serviceTask >
< serviceTask id=“sid-A7731860-F9D4-49BF-8E99-D8A91305A23F” name=“Step-2” flowable:class=“com.amex.imdp.Step2” >< /serviceTask >
< startEvent id=“sid-53BDE9A8-9931-4568-8546-9D7A6B896B84” >< /startEvent >
< endEvent id=“sid-DD0DF0DB-612B-4710-B6AC-65080B019C85” >< /endEvent >
< sequenceFlow id=“sid-38A990BE-9278-4074-A60A-516ECF18A2EC” sourceRef=“sid-219B212D-1E92-4AF9-8989-0CE7C2C441F1” targetRef=“sid-A7731860-F9D4-49BF-8E99-D8A91305A23F” >< /sequenceFlow >
< sequenceFlow id=“sid-73DF728B-B4A2-46D9-9E66-817DC0776474” sourceRef=“sid-53BDE9A8-9931-4568-8546-9D7A6B896B84” targetRef=“sid-219B212D-1E92-4AF9-8989-0CE7C2C441F1” >< /sequenceFlow >
< sequenceFlow id=“sid-0BDC3515-D863-470D-A7BB-84DC2D8BB87A” sourceRef=“sid-A7731860-F9D4-49BF-8E99-D8A91305A23F” targetRef=“sid-DD0DF0DB-612B-4710-B6AC-65080B019C85” >< /sequenceFlow >
< /subProcess >
< boundaryEvent id=“Step1Failed” name=“Step1Failed” attachedToRef=“sid-5CB9EA76-69A8-4E92-B97D-DA237F5852AE” >
< errorEventDefinition errorRef=“Step1Failed” >< /errorEventDefinition >
< /boundaryEvent >
< endEvent id=“sid-F71EF7BD-ED98-4FB0-ADEC-376F1145C5C0” >< /endEvent >
< sequenceFlow id=“sid-E813498B-CC02-43F2-BCC3-F6C5292490DE” sourceRef=“Step1Failed” targetRef=“sid-F71EF7BD-ED98-4FB0-ADEC-376F1145C5C0” >< /sequenceFlow >
< /process >
My need is that if BPMN Error is thrown, then Step-2 should never be executed. But in my case , Step-2 is getting executed. Can you please suggest what is missing .
Thanks
Vinay
@tijs Flow is not going to the Boundary Error Event , can you suggest what is missing ?
joram
June 6, 2017, 9:47am
5
You’re not throwing the error, you’re making a new object.
So, instead of
new BpmnError("Step1Failed", ex.getMessage());
you need to add ‘throw’ before it:
throw new BpmnError("Step1Failed", ex.getMessage());
Can’t believe I can be so dumb .
Thanks @joram for pointing out the issue. Its working as expected now.
Thanks Again.