2017 June Release

Defining conditions, case statements and loopsPermanent link for this heading

A process can include several types of control elements that allow you to define which path should be taken in a process depending on the result of a predefined expression.

Defining a conditionPermanent link for this heading

Syntax

if reference_opt (condition) {
  // Activity definitions or control elements
  ...
}
else {
  // Activity definitions or control elements
  ...
}


The if and else keywords denote a condition in a process. A conditional statement embedded into a process allows you to control which path should be taken in a process depending on whether the expression defined in the condition evaluates to true or false. In addition an optional reference may be given.

If the condition evaluates to true, the block following the if statement is executed. Otherwise, the execution continues in the else block. The else block, however, is optional.

When the condition is evaluated, a dictionary is made available in the local scope this that contains the entries listed in chapter “Using an expression to implement a step”– except for workitem, which is not available in this context.

Example

processes APPDUCXSAMPLE@200.200
{
  import COOSYSTEM@1.1;
  import COOWF@1.1;

  process OrderWF {
    // Activity for approving an order
    activity {
      actor {
        pos = DeptManager;
        orgunit = OrderProcessing;
      }
      step ViewOrder multiple {
        execute = ViewOrder;
      }
      step ApproveOrder required leave {
        execute = expression {
          object.ObjectLock(true, true);
          object.orderstate = OrderState(OS_APPROVED);
        }
      }
      step DenyApproval required leave {
        execute = expression {
          object.ObjectLock(true, true);
          object.orderstate = OrderState(OS_DISCARDED);
        }
      }
    }
    if (object.orderstate == OrderState(OS_APPROVED)) {
      // Activity for shipping the order
      activity ShippingAct {
        ...
      }
      // Activity for billing the order
      activity {
        ...
      }
    }
    else {
      // Activity for handling discarded orders
      activity {
        ...
      }
    }
  }
}

Defining a case statementPermanent link for this heading

Syntax

switch reference_opt (enumerationproperty) {
case enumerationitem:
  // Activity definitions or control elements
  ...
default:
  // Activity definitions or control elements
  ...
}


A case statement allows you to define different process paths depending on the value of an enumeration property of the business object the process is attached to.

The switch keyword is used to define a case statement. It must be followed by parentheses and curly braces, and the reference of the enumeration property to be evaluated must be enclosed in the parentheses. In addition an optional reference may be given.

The switch block may contain case sections for each enumeration item. The case keyword must be followed by the reference of the enumeration item and a colon. You can also define a single case section for multiple enumeration items by separating the enumeration items by a comma. The default keyword can be used to define a default section applying to all enumeration values that are not handled in an appropriate case section.

Example

processes APPDUCXSAMPLE@200.200
{
  import COOSYSTEM@1.1;
  import COOWF@1.1;

  process CustomerWF {
    switch (customertype) {
    case CT_ENDUSER:
      activity {
        step AssignOrderToEndUser {
          ...
        }
      }

    case CT_RETAILER, CT_WHOLESALER:
      activity {
        step AssignOrderToReseller {
          ...
        }
      }

    default:
      activity {
        step AssignOrder {
          ...
        }
      }
    }
  }
}

Defining a loopPermanent link for this heading

Syntax

repeat reference_opt {
  // Activity definitions or control elements
  ...
} until (terminationcondition);


The repeat and until keywords can be used to define a loop in a process. The loop is executed until the expression defined in parentheses after the until keyword – referred to as termination condition – evaluates to false. In addition an optional reference may be given.

When the termination condition is evaluated, a dictionary is made available in the local scope this that contains the entries listed in chapter “Using an expression to implement a step”– except for workitem, which is not available in this context.

Example

processes APPDUCXSAMPLE@200.200
{
  import COOSYSTEM@1.1;
  import COOWF@1.1;

  process CustomerWF {
    repeat reference_opt {
      // Activities and control elements for processing an order
      activity {
        ...
      }
      activity {
        ...
      }
    } until (object.orderstate == OrderState(OS_COMPLETED));
  }
}

Defining a gatewayPermanent link for this heading

Syntax

gateway reference_opt {
  type = gatewaytype;

  // Path definitions
  path (pathcondition) {

    reference = "reference1";

    // Activity definitions or control elements

    end;

  }

  path (pathcondition) {

    reference = "reference2";

    // Activity definitions or control elements

    end;

  }

  default {

   reference = "reference3";

    // Activity definitions or control elements
  }
}


The gateway keyword can be used to define exclusive and inclusive gateways in a process. In addition an optional reference may be given.

If the type equals GWT_EXCLUSIVE, the conditions of the paths are evaluated and only the first path, where the condition evaluated to true, will be executed. Choosing the type GWT_INCLUSIVE leads to the result that all paths with a condition evaluated to true will be executed.

Example

processes APPDUCXSAMPLE@200.200
{
  import COOSYSTEM@1.1;
  import COOWF@1.1;

  process CustomerWF {
    gateway {

      type = GWT_EXCLUSIVE;
      path (cooobj.objname contains "Default") {

        reference = "reference1";

        sequence {
          activity {
            ...
          }

        }

        end;
      }
      default {

        reference = "reference1";

        sequence {
          activity {
            ...
          }

        }
      }
    }

  }
}

Paths of gateways can lead to the explicit termination of the current process. This can be denoted by the keywords “end”, “terminate” or “error”. “end” ends the current process, “terminate” terminates the execution of the current process and “error” indicates that the process needs to be terminated due to an eror.