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