Java API for Workflows

Complete documentation for API functionality related to workflows can be found in the API documentation accessible at [system]/sdk or by clicking the Technical Documentation button on the Start Page. This topic provides some introductory information and simple examples, but should not be considered comprehensive.

In the Public Java API "WorkflowableNode" is the main interface for Workflow related functionality. All the "workflowable" node types inherit the interface and thus you can call the available methods from the node shorthand.

If, for instance, you wanted to get the time where an object entered a specific state, on entry to the state you could have a business action with a script like the one below, storing the entry time in the script variable "entryTime".

var entryTime = node.getTaskByID("Workflow ID", "State ID").getEntryTime();

The getTaskByID() method from the WorkflowableNode interface is called on node. This returns a Task that has the getEntryTime() method (refer to the Task interface).

Note that this script will only work if the object is actually in the workflow with the specified ID and in the state with the specified ID.

From a business rule used in a workflow (e.g., a local rule within the workflow itself), you can typically be pretty sure that the object is in fact in the workflow. However, if you run from a business rule used elsewhere in STEP and wanted to check whether an object was in a given flow, you could write something like:

if(node.getWorkflowInstanceByID("Workflow ID")) {
	// Object is in Workflow - do something
}
else {
	// Object is not in Workflow - do something else
}

Thus, if the object is not in the workflow, the method returns "null" - a "false" value in JavaScript.

While in the entry time example above you could be sure that you were in the workflow, likewise if you ran the script on entry to the state referenced with "State ID", you could be sure that you were in that state. However, if you are working with parallels, to do something with a task on a state that is not the same as the one you are running the business rule from. In that case it would make sense to start your script with a check for whether your object is actually in that other state:

var task = node.getTaskByID("Workflow ID", "ID of another State"); 
if(task) {
  var entryTime = task.getEntryTime();
}
else {
  logger.warning("Object with ID '" + node.getID() + "' is not in expected State");
}

The two primary interfaces available through the WorkflowableNode interface are Task and WorkflowInstance. Via the Task interface you have methods available that relate to a given object-in-state-in-workflow relation. WorkflowInstance meanwhile gives you access to the methods relating to the object-in-workflow relation. In the Workflow Variables topic of the Advanced Workflow topics documentation (here), the concept of workflow variables is described. These variables live on the object-in-workflow relation and can thus be manipulated via the WorkflowInstance interface.