This scenario shows how to create an instance of a task template
that defines a human task and start the task instance.
- 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),
null);
The results are sorted by name.
The query returns an array containing the first 50 sorted human task templates.
- 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");
}
- 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
null);
Work
items are created for the people concerned with the task instance. For example,
a potential owner can claim the new task instance.
- 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.