IBM BPM, V8.0.1, All platforms > Programming IBM BPM > Developing client applications for BPEL processes and tasks > Developing EJB client applications > Developing applications for BPEL processes

Processing a page flow that starts with the BPEL process

Some workflows are performed by only one person, for example, ordering books from an online bookstore. This type of workflow has no parallel paths. This example shows how to use the initiateAndClaimFirst and completeAndClaimSuccessor APIs to process this type of workflow.

Ensure that the process model that contains the page flow meets the following criteria:

A page flow is also referred to as a single person workflow or a screen flow. There are two kinds of page flows:

Server-side page flows are more powerful than client-side page flows, but they consume more server resources to process them. Therefore, consider using this type of workflow primarily in the following situations:

In many situations, using a mix of server-side and client-side page flows is appropriate. This example shows a server-side page flow.

A typical example of a page flow is the ordering process in an online bookstore, where the purchaser completes a sequence of actions to order a book. This sequence of actions can be implemented as a series of human task activities (to-do tasks). If the purchaser decides to order several books, this is equivalent to starting an order process, and claiming the next human task activity.

The initiateAndClaimFirst API starts the page flow, that is, it starts the specified process and claims the first human task activity in the sequence of activities. It returns information about the claimed activity, including the input message to be worked on.

The completeAndClaimSuccessor API then completes the human task activity and claims the next one in the same process instance for the logged-on person. The API returns information about the next claimed activity, including the input message to be worked on.

Compare this example with the example of a page flow that is started by a to-do task.


Procedure

  1. Start the book ordering process and claim the first activity in the sequence of activities. Start the process with an input message of the appropriate type. When you create the message, you must specify its message type name so that the message definition is contained. If you specify a process instance name, it must not start with an underscore. If a process instance name is not specified, the process instance ID (PIID) in String format is used as the name.

    1. Retrieve the process template to create an input message of the appropriate type.
      ProcessTemplateData template = process.getProcessTemplate("CustomerOrder");
      ClientObjectWrapper input = process.createMessage(template.getID(),                             template.getInputMessageTypeName());
      DataObject myMessage = null;
      if ( input.getObject()!= null && input.getObject() instanceof DataObject )
      {
        myMessage = (DataObject)input.getObject();
        //set the strings in the message, for example, a customer name   myMessage.setString("CustomerName", "Smith");}

    2. Start the process and claim the first human task activity.
      InitiateAndClaimFirstResult result = 
        process.initiateAndClaimFirst("CustomerOrder", "MyOrderProcess", input);
      AIID aiid = result.getAIID(); 
      ClientObjectWrapper input = result.getInputMessage();
    When the first activity is claimed, the input message and the ID of the claimed activity is returned.

  2. When work on the activity is finished, complete the activity, and claim the next activity.

    To complete the activity, an output message is passed. When you create the output message, you must specify the message type name so that the message definition is contained.

    ActivityInstanceData activity = process.getActivityInstance(aiid);
    ClientObjectWrapper output = 
          process.createMessage(aiid, activity.getOutputMessageTypeName());
    DataObject myMessage = null ;
    if ( output.getObject()!= null && output.getObject() instanceof DataObject )
    {
      myMessage = (DataObject)output.getObject();
      //set the parts in your message, for example, an order number   myMessage.setInt("OrderNo", 4711);} 
    //complete the activity and claim the next one CompleteAndClaimSuccessorResult successor = 
       process.completeAndClaimSuccessor(aiid, output);
    This action sets an output message that contains the order number and claims the next activity in the sequence. If AutoClaim is set for successor activities and if there are multiple paths that can be followed, all of the successor activities are claimed and a random activity is returned as the next activity. If there are no more successor activities that can be assigned to this user, Null is returned.

    If the process contains parallel paths that can be followed and these paths contain human task activities for which the logged-on user is a potential owner of more than one of these activities, a random activity is claimed automatically and returned as the next activity.

  3. Work on the next activity.
    String name = successor.getActivityName();
    
    ClientObjectWrapper nextInput = successor.getInputMessage();
    if ( nextInput.getObject()!= 
                   null && nextInput.getObject() instanceof DataObject )
    {
      activityInput = (DataObject)input.getObject();
      // read the values   ...}  
    
    aiid = successor.getAIID();
  4. Continue with step 2 to complete the activity.

Developing applications for BPEL processes


Related concepts:
Transactional behavior of long-running BPEL processes


Related tasks:
Processing a page flow that is started by a to-do task


Related reference:
BPEL process editor: Server tab