Running Background Processes from Workflows

Via the API Task interface, it is possible to start a background process, BGP, and have events triggered on the task matching the end status of the background process. Image below shows a simple workflow where an Approve Recursively Background Process is started when entering the 'Trigger_BGP' state. When the background process is done, one of the transitions out of the state will be performed based on the end status of the background process. i.e., If the end status is 'succeeded', the "bgp.succeeded" event will be triggered. If it is failed, the "bgp.failed" event will be triggered. Similar to the 'StateID.Something' (where 'Something' stands for the user's word choice) and 'stibo.import' events, any event beginning with 'bgp.' will be hidden in the STEP Workflow Items editor and on the Object Tasks tab.

In the picture below, as soon as a task is released to the 'Trigger_BGP' state, the Approve Recursively with a BGP process script will execute.

Once a BGP has finished, if a particular task / item needs to be investigated, a user can navigate to its State Log tab and view all Background Process IDs that occurred.

Should the user need to examine any background process information further, they can do so by either going to the main BG Processes tab and looking at the background processes for the receptive workflow or by searching for the Background Process ID.

If the BGP should fail, looking at the BGP report can help in determining why.

In the case of this 'Approve Recursively' workflow example, the task will be moved to the Failure state, and only once the error is fixed, then the task can be moved from the Failure state by selecting the event 'Try_Again'. Then if the BGP is successful, it will move to the Success state.

On Entry Background Process Script

While the script below could be used for other scenarios, two scenarios that this script can be used with workflow for are the following:

  1. If an object is required to run a translation, and it is mandatory that an object is in the approved state before running the translation.
  2. If there is any extraction required from the Approved workspace

The On Entry script that starts the background process is shown below. The last line stores the ID of the started background process in a workflow variable with ID 'BGP ID'. The ApproveRecursiveServiceDescriptor is described in the public API documentation, accessed by clicking the Technical Documentation button on the Start Page.

var task = node.getTaskByID("WorkflowID", "WorkflowStateID");
var serviceDescriptor = com.stibo.services.base.approverecursive.ApproveRecursiveServiceDescriptor;
var parameter = new serviceDescriptor.Parameter();
parameter.context = step.getCurrentContext();
parameter.nodes = [node];
var bgp = task.startBackgroundProcess(serviceDescriptor, parameter, "Started from Workflow");
node.getWorkflowInstance(workflow).setSimpleVariable("WorkflowVariableID", bgp.getID());

Note: The 'WorkflowID' and 'WorkflowStateID' in the top line, and 'WorkflowVariableID' in the bottom should be replaced by the users desired workflow information.

The On Entry script in the state 'Trigger_BGP' will look like the image below. Also notice that the image below has filled in the appropriate 'WorkflowID,' 'WorkflowStateID,' and 'WorkflowVariableID' in accordance to the workflow information.