基本管理 > 支援協同合作 > 工作流程管理 > 工作流程工具 > 工作流程範本管理 > 工作流程程式碼範例 > 同步自動機制範例 > 流程實例之間的同步
  
流程實例之間的同步
本主題提供一個「同步」自動機制節點範例,該節點可接聽活動狀態的變更。
參考的工作流程
SynchronizationAccrossProcessInstances.xml
SynchronizeProcessInstance.xml
描述
這一類的同步與獨立流程的同步十分類似,唯一的差異是,自動機制接聽的是 wt.workflow.engine.WfProcess 的 ACTIVITY_STATE_CHANGED 事件,而非 WfAssignedActivity。在下列運算式中,自動機制會檢查發出 State_Changed 事件的流程是否與其關注的流程相同。如果是,自動機制就會依據流程狀態執行路由作業。
指示
processName 是自動機制的父流程內所定義的變數。它代表自動機制所要的流程名稱。
* 
很可能有超過一個流程的名稱為 "processName"。
複製下述的程式碼:
//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";
}
}