Basic Administration > Supporting Collaboration > Workflow Administration > Workflow Tools > Workflow Template Administration > Workflow Code Samples > Synchronize Robot Samples > Synchronize Parent Child Process
  
Synchronize Parent Child Process
This topic provides a sample of the Synchronize robot node listening for a change in the activity state of the event that generated the parent's workflow process.
Referenced Workflow
SynchronizationOnParentChildProcess.xml
SynchronizeChildProcess.xml
Description
The expression below is for a robot that listens to an ACTIVITY_STATE_CHANGED event emitted by an assigned activity node. The expression screens to see if the activity that emitted the event belongs to a process that spawned the parent process of the robot. If so, it fires the appropriate routing event based on the state of the activity.
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 robot belongs to a first-level process, that is, it does not exist in a nested subprocess. The robot has to have knowledge of the structure of the nested subprocesses in order to get access to the outermost process in the workflow template.
Copy the following code:
//Get the Activity that triggered the State_change event.
wt.workflow.engine.WfActivity activity = (( wt.workflow.engine.WfActivity ) (((wt.events.KeyedEvent)event).getEventTarget()));

//get the process that the Activity belongs to
wt.workflow.engine.WfProcess activityParentProcess = activity.getParentProcess();

//Get the Parent of that sub process
wt.fc.ObjectReference activityParentRef = activity.getParentProcessRef( );

//Get the parent process for the Synch Robot
wt.workflow.engine.WfProcess mySubProcess = ( wt.workflow.engine.WfProcess ) self.getObject( );

/Get the parent process that spawns this sub process
wt.workflow.engine.WfActivity myRequestorActivity = (( wt.workflow.engine.WfActivity ) mySubProcess.getRequester( ));
wt.workflow.engine.WfProcess myParentProcess = myRequestorActivity.getParentProcess( );

//Check if the parent of the activity and the parent process of the subprocess that the Synch robot belongs to are the same.
if ( wt.fc.PersistenceHelper.isEquivalent(activityParentProcess , myParentProcess )){

//If the state of the Activity in the ParentProcess is executed, set result to "completed" and ifterminated, set result to "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";
}
}