Creating and starting a task instance

This scenario shows how to create an instance of a task template that defines a human task and start the task instance.

Steps for this task

  1. Optional: List the task templates to find the name of the originating task you want to run.

    This step is optional if you already know the name of the task.

    TaskTemplate[] taskTemplates = task.queryTaskTemplates
    ("TASK_TEMPL.KIND=TASK_TEMPL.KIND.KIND_HUMAN",
     "TASK_TEMPL.NAME",
      new Integer(50),
      (TimeZone)null);

    The results are sorted by name. The query returns an array containing the first 50 sorted human task templates.

  2. Create an input message of the appropriate type.
    TaskTemplate template = taskTemplates[0];
    
    // create a message for the selected task
    ClientObjectWrapper input = task.createInputMessage( template.getID());                       
    DataObject myMessage = null ;
    if ( input.getObject()!= null && input.getObject() instanceof DataObject )
    {
      myMessage = (DataObject)input.getObject();
      //set the parts in the message, for example, a customer name
      myMessage.setString("CustomerName", "Smith");
    }
  3. Create and start the human task; a reply handler is not specified in this example.

    The example uses the createAndStartTask method to create and start the task.

    TKIID tkiid = task.createAndStartTask( template.getName(), 
                                           template.getNamespace(),
                                           input,
                                           (ReplyHandlerWrapper)null);

    Work items are created for the people concerned with the task instance. For example, a potential owner can claim the new task instance.

  4. Claim the task instance.
    ClientObjectWrapper input2 = task.claim(tkiid);
    DataObject taskInput = null ;
    if ( input2.getObject()!= null && input2.getObject() instanceof DataObject )
    {
      taskInput = (DataObject)input2.getObject();
      // read the values
      ...
    }  

    When the task instance is claimed, the input message of the task is returned.


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