Basic Administration > Supporting Collaboration > Workflow Administration > Workflow Tools > Workflow Template Administration > Workflow Code Samples > Synchronize Robot Samples > Synchronize on Sibling Subprocesses
  
Synchronize on Sibling Subprocesses
This topic provides a sample of the Synchronize robot node listening for a change in the activity state of a parent's subprocess.
Referenced Workflows
SynchronizingOnSiblingSubProcess.xml
SiblingSubProcess.xml
Description
The expression below is for a robot that listens to an ACTIVITY_STATE_CHANGED event emitted by an assigned activity. The expression screens to see if the activity node that emitted the event belongs to one of the subprocesses of the parent workflow template that the Synchronize robot node belongs to. If so, it fires the appropriate routing event based on the state of the activity node.
Instructions
The robot in this case listens to the ACTIVITY_STATE_CHANGED event and the Windchill class to pay attention to is wt.workflow.work.WfAssignedActivity.
This sample assumes that the activity belongs to a first-level process, that is, it does not exist in a nested subprocess. It is possible to track down such an activity, but this would require the robot to have knowledge of the structure of the nested subprocesses.
Copy the following code:
//Get the Activity that generated the event
wt.workflow.engine.WfActivity activity = (( wt.workflow.engine.WfActivity ) (((wt.events.KeyedEvent)event).getEventTarget()));

//Get the sub process that the Activity belongs to
wt.workflow.engine.WfProcess subProcess = activity.getParentProcess();

//Get the Parent of that sub process
wt.workflow.engine.WfProcess activityParentProcess = (( wt.workflow.engine.WfActivity ) subProcess.getRequester( )). getParentProcess( );

//Get the parent process of the Synch robot that has this expression
wt.workflow.engine.WfProcess myParentProcess = ( wt.workflow.engine.WfProcess ) self.getObject( );

//If the object IDs of the parent of the activity and the parent of the Synch Robot are the same,check for the state of the activity.
if ( wt.fc.PersistenceHelper.isEquivalent(activityParentProcess , myParentProcess )){

//If the Activity has been executed, set result to "completed" and if it has been terminated, setresult to "terminated". Else wait //for a state change.
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";
}
}