Synchronize Independent Processes
This topic provides a sample of a Synchronize robot node halting a process until an activity node of a separate workflow process reaches a certain state.
Referenced Workflows
SynchronizationOfIndependentProcesses.xml
SynchronizeIndependentProcess.xml
Description
A Synchronization robot node can halt the progress of a workflow process until an activity in a separate workflow process reaches a certain state. The code below can be an expression for such a robot. The class to listen to is wt.workflow.work.WfAssignedActivity and the event to listen to is ACTIVITY_STATE_CHANGED. The robot checks if the activity that triggered this event and its parent process are the same ones that have been provided to it, and if so, it routes based on the state of the activity. In order to identify the parent workflow template of the activity, it must know the names of both the activity and its parent workflow template. This can be a variable in the process that the robot belongs to.
Instructions
activityName and otherProcessName represent variables in the workflow template that hold string values representing the name of the activity and process that the robot is listening for.
* 
There could be more than one process with the same name. In order to use this sample, you need to ensure either that only one process is called "processName" or that all processes that have this name are instances of the same workflow template.
Copy the following code:
//get the activity that emitted the event
wt.workflow.engine.WfActivity activity = ( wt.workflow.engine.WfActivity ) ((wt.events.KeyedEvent) event).getEventTarget();

//Check if this activity is the same as the one we are interested in
if (activity.getName().equals(activityName)) {

//Get the parent process of the activity.
wt.workflow.engine.WfProcess activityParent = activity.getParentProcess();

//Check if the parent process of the activity is the same one we are interested in.
if (( activityParent.getName( )). equals(otherProcessName )) {

//Set result to "completed" if the activity has been executed and to "terminated" if it has been terminated. Else check again.
if ( wt.workflow.engine.WfState.CLOSED_COMPLETED_EXECUTED.equals(activity.getState( ))){
result = "completed";
}
else if ( wt.workflow.engine.WfState.CLOSED_TERMINATED.equals(activity.getState( ))){
result = "terminated";
}
}
}
Was this helpful?