同步化父子流程
本主題提供一個「同步」自動機制節點範例,該節點可接聽生成父工作流程的事件的活動狀態變更。
參考的工作流程
SynchronizationOnParentChildProcess.xml
SynchronizeChildProcess.xml
描述
以下的運算式,是用於會接聽由一個指派的活動節點所發出的 ACTIVITY_STATE_CHANGED 事件的自動機制。此運算式會篩選檢查發出該事件的活動,是否屬於生成自動機制的父流程之流程。若是,則它會根據該活動的狀態,而觸發適當的路由事件。
指示
在此例中的自動機制會接聽 ACTIVITY_STATE_CHANGED 事件,需留意的 Windchill 類別是 wt.workflow.work.WfAssignedActivity。
本範例假設自動機制屬於第一階層的流程,也就是說,它不是在巢狀子流程內。自動機制將必須對該巢狀子流程的結構有所了解,才能夠存取該工作流程範本中最外層的流程。
複製下述的程式碼:
//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";
}
}
這是否有幫助?