Sending a message to a waiting activity

Why and when to perform this task

Pick, receive, and onMessage activities can be used to synchronize a running process with events from the "outside world". For example, the receipt of an e-mail from a customer in response to a request for information might be such an event.

Steps for this task

  1. List the activity service templates that are waiting for a message from the logged-on user.
    QueryResultSet result = 
       process.query("ACTIVITY_SERVICE.VTID,ACTIVITY.ATID", 
                     "ACTIVITY.STATE=ACTIVITY.STATE.STATE_WAITING AND
                      ACTIVITY_SERVICE.PORT_TYPE='Confectionery' AND
                      ACTIVITY_SERVICE.OPERATION='OrderRequest' AND
                      WORK_ITEM.REASON=WORK_ITEM.REASON.REASON_POTENTIAL_OWNER",
                      null, null, null); 
  2. Send a message.

    The caller must be a potential owner of the activity that receives the message, or an administrator of the process instance.

    if ( result.size() > 0 )
    {
      result.first();
      VTID vtid = (VTID)result.getOID(1);
      ATID atid = (ATID)result.getOID(2); 
      ActivityServiceTemplateData activity = 
              process.getActivityServiceTemplate(vtid,atid);
    
      // create a message for the service to be called
      ClientObjectWrapper message = 
            process.createMessage(vtid,atid,activity.getInputMessageTypeName()); 
      DataObject myMessage = null;
      if ( message.getObject()!= null && message.getObject() instanceof DataObject )
      {
        myMessage = (DataObject)message.getObject();
        //set the strings in the message, for example, chocolate is to be ordered
        myMessage.setString("Order", "chocolate");
      }
    
      // send the message to the waiting activity 
      process.sendMessage(vtid, atid, message);  
    }

    This action sends the specified message to the waiting activity service and passes some order data.

    You can also specify the process instance ID to ensure that the message is sent to the specified process instance. If the process instance ID is not specified, the message is sent to the activity service, and the process instance that is identified by the correlation values in the message. If the process instance ID is specified, the process instance that is found using the correlation values is checked to ensure that it has the specified process instance ID.

Related concepts
Queries on business-process and task-related objects

Terms of use | | Broken links

Last updated: Mon Mar 27 18:04:06 2006

(c) Copyright IBM Corporation 2005.
This information center is powered by Eclipse technology (http://www.eclipse.org)