1

I am working on a BPMN file which has a dataObject and and some serviceTasks. I want to check whether the serviceTask variable is present in dataObject or not. If it is present, the service task should be skipped. So, I am using skipExpressions to achieve this.

Here is the sample BPMN:

<process id="TASK_FLOW_TESTING" name="TASK_FLOW_TESTING" isExecutable="true">
<dataObject id="optionalInputList" name="optionalInputList">
       <extensionElements>
           <flowable:value>
                   ["input1","input2"]
           </flowable:value>
       </extensionElements>
   </dataObject>
<dataObject id="_ACTIVITI_SKIP_EXPRESSION_ENABLED" name="_ACTIVITI_SKIP_EXPRESSION_ENABLED" itemSubjectRef="xsd:boolean">
  <extensionElements>
    <flowable:value>true</flowable:value>
  </extensionElements>
</dataObject>
  <serviceTask id="REFRESH_TASK" name="REFRESH_TASK" flowable:async="true" skipExpression="/*something should be here*/" flowable:triggerable="true" flowable:class="com.delegates.customDelegate">
     <extensionElements>
        <flowable:field name="inputData">
           <flowable:string>["input1"]</flowable:string>
        </flowable:field>
        <flowable:field name="outputDataConfig">
           <flowable:string>["output1"]</flowable:string>
        </flowable:field>
     </extensionElements>
  </serviceTask>

I want to skip refresh task if my input1 is present in optionalInputList of dataObject. Can I achieve this inside BPMN ?

Jim Moriarty
  • 141
  • 1
  • 5
  • 12

1 Answers1

1

In order to enable skip expressions, you need to set the _ACTIVITI_SKIP_EXPRESSION_ENABLED field to true as a variable. You have correctly done this by defining a dataObject with the variable demonstrated in your bpmn20.xml.

Next, your skip_expression as any other expression in flowable expects a true or false result and is evaluated before your service task's execution expression,DelegateExpression,Class etc.. I have defined the skip_expression to execute a method in a Spring Bean that returns either true(task skipped) or false(task executed)

<serviceTask id="sid-80A94367-049B-4851-BD97-DC1A368DAB9F" name="Some service" flowable:expression="${serviceTaskBean.execute(execution)}" flowable:skipExpression="${serviceTaskBean.skipExpressionLogic(optionalInputList)}"></serviceTask>

where the input to the method is the value of your optionalInputList dataObject

The Service Task Bean :

public class ServiceTaskBean {

    public void execute(DelegateExecution execution) {
        //some service execution logic executed only if the 
        //skipExpressionLogic method below returns false

    }
    public boolean skipExpressionLogic(String optionalInputList) {
        try {
            //The values set in your dataObject appears in 
             //optionalInputList
            if(optionalInputList.contains("input1")) {
                return true; //task skipped
            }
            else {
                return false; //task executed
            }

        }catch(Exception e) {
            e.printStackTrace();
        }
    return false;
    }
}

more info on using expressions here : https://www.flowable.com/open-source/docs/bpmn/ch04-API#expressions

Saideep Ullal
  • 221
  • 3
  • 16