Basic Administration > Supporting Collaboration > Workflow Administration > Workflow Tools > Workflow Template Administration > Workflow Code Samples > Synchronize Robot Samples > Synchronize Across Process Instances
  
Synchronize Across Process Instances
This topic provides a sample of a Synchronize robot node listening for a change in the activity state
Referenced Workflows
SynchronizationAccrossProcessInstances.xml
SynchronizeProcessInstance.xml
Description
This type of synchronization is very similar to the synchronization of independent processes; the only difference is that, in this case, the robot listens to the ACTIVITY_STATE_CHANGED event of the wt.workflow.engine.WfProcess instead of the WfAssignedActivity. In the expression below, the robot checks if the process that emitted the State_Changed event is the same one that it is interested in. If so, it performs a routing based on the state of the process.
Instructions
processName is a variable defined in the parent process of the robot. It represents the name of a process that is of interest to the robot.
* 
It is possible that more than one process has the name "processName".
Copy the following code:
//get the process that emitted the event
wt.workflow.engine.WfProcess processInstance = ( wt.workflow.engine.WfProcess ) ((wt.events.KeyedEvent)event).getEventTarget();

//Check if the process that triggered the event is the same one we are interested in.
if ( processInstance.getName( ).equals(processName)){

//If so, check for the state of the process. Set result to "completed" if the process has been successfully completed
// and to "terminated" if the process has been terminated. In all other cases, check again.

if ( wt.workflow.engine.WfState.CLOSED_COMPLETED_EXECUTED.equals(processInstance.getState( ))){

result= "completed";

}

else if ( wt.workflow.engine.WfState.CLOSED_TERMINATED.equals(processInstance.getState( ))){

result= "terminated";
}
}