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:
To facilitate development, you may 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 using VWWorkflowDefinition.readFromFile().
Note: A local workflow definition (a *.pep file) must already exist. Use either the VWWorkflowDefinition constructor, or the constructor for the WFDefinitionSample sample class.
If the workflow has already been transferred to the Process database and has not been changed, transfer is not necessary. However, if the workflow has not yet been transferred, or if there has been a change in the workflow, transfer is required.
Transfer the workflow definition object to the Process database using VWSession.transfer(). Specify the Content 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 transferring the workflow definition object to the Process 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 using VWTransferResult.getVersion().
When you create the workflow using VWSession.createWorkflow(), use the version string returned from VWTransferResult.getVersion() as the argument to a VWStepElement call.
Create an instance of the workflow using VWSession.createWorkflow(). VWSession.createWorkflow() returns a VWStepElement object representing 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 required of a Launch Step Processor is to launch (start) the workflow.
Use VWStepElement.doDispatch to launch a workflow. The doDispatch() method saves changes made to the Work Object associated with the Step Element to the Process database and goes to the next step defined in the workflow definition.