Creating a workflow instance is a prerequisite set of operations for a Launch Step Processor to launch a workflow.
To create a workflow instance, create a class to do the following actions:
To facilitate development, you might want to adapt the API sample constructor for LaunchSample.
Create a workflow definition object from an object store, file store, or Content Services library file by using VWWorkflowDefinition.readFromFile().
Note: A local workflow definition (a *.pep file) must exist. Use either the VWWorkflowDefinition constructor, or the constructor for the WFDefinitionSample sample class.
If the workflow was already transferred to the Process database and was not changed, the transfer is not necessary. However, if the workflow was not transferred, or if there was a change in the workflow, the transfer is required.
Transfer the workflow definition object to the Process database by using VWSession.transfer(). Specify the Content Platform Engine (or Content Services) docid as a parameter to identify the workflow definition. For example:
// Transfer the workflow definition object, where the second parameter is a unique id.
VWTransferResult transferResult = m_vwSession.transfer(wflDef, uniqueid, false, true);
After you transfer the workflow definition object to the database, validate and log whether the transfer was successful, and display the transfer errors.
if (transferResult.success()) {
m_logger.log("The transfer was successful.")
// ( less significant code . . . )
}
else {
// Display the transfer errors.
String[] errorArray = transferResult.getErrors();
if (errorArray != null)
m_logger.log("\tThe following transfer errors occurred: ", errorArray);
else
m_logger.log("\t\tError messages were not available.");
}
Prepare to create the Launch step by retrieving the version that uses VWTransferResult.getVersion().
When you create the workflow that uses VWSession.createWorkflow(), use the version string that is returned from VWTransferResult.getVersion() as the argument to a VWStepElement call.
Create an instance of the workflow that uses VWSession.createWorkflow(), which returns a VWStepElement object that represents the Launch step for the workflow.
You can use VWStepElement.setComment() to label this Launch step. For example:
launchStep = m_vwSession.createWorkflow(vwVersion);
launchStep.setComment("This is a sample workflow Launch step comment");
See also Updating Workflow Data.
The final operation that is required of a Launch Step Processor is to launch the workflow.
Use VWStepElement.doDispatch to launch a workflow. The doDispatch() method saves changes to the database and dispatches the Work Object to the next step that is defined in the workflow definition. The saved changes are those changes that were made to the Work Object that is associated with the Step Element.