具有多個計量呼叫的計量運算式
本主題提供了一個範例,示範如何使用多個計量呼叫的計量運算式及避免兩次觸發相同的事件。
參考的工作流程
TallyExpressionWithTwoTallyCalls.xml
描述
在同一個運算式之內可能會有多個計量呼叫。這種情況下,就可能將同一個路由事件多次地新增到事件清單上。若要避免發生這種情況,請使用 setEvents( ) 方法,如範例中所示。此方法會收集非重複的路由事件,如此清單中的每個路由事件都只會觸發一次。下面的運算式會輪詢選擇「測試」的次數,並會將結果儲存至向量 tallyResults。然後,它會輪詢選擇「修改」而不是其他兩個的工作負責人的百分比。現在將此投票結果加入向量 tallyResults。使用 setEvents 方法會防止事件「修改」(出現在兩個計量呼叫中) 在要觸發的事件清單中出現兩次。然後結果會設定為向量 tallyResults。
指示
這項活動的路由事件數目不一。只有工作流程定義中已選為必須的工作負責人,其所投的票才可用於調查。
複製下述的程式碼:
//Create a vector that will hold all the non-duplicated UserEvents chosen for this activity.
Vector tallyResults = new Vector( );
//Get the object representing this activity.
wt.workflow.work.WfAssignedActivity mySelf = (( wt.workflow.work.WfAssignedActivity ) self.getObject( ));
//Get all the UserEvents for this activity. The resulting Vector may hold duplicate values of some events.
Vector userEvents = (Vector) mySelf.getUserEventList( );
//If "Test" receives 2 or more of the required votes, get "Test", else get "Modify".
//Collect the non-duplicated events into the Vector tallyResults ( i.e add only those events that do not already exist in the vector.
WfTally.setEvents(tallyResults , wt.workflow.work.WfTally.number(self , WfTally.GTE, 2, "Test", "Modify"));
//If "Modify" receives more than 35% of the required votes, get "Modify" else get "Approve and Release".
//Collect the non-duplicated events into the Vector tallyResults ( i.e add only those events that do not already exist in the vector.
WfTally.setEvents(tallyResults , wt.workflow.work.WfTally.percent(self , WfTally.GT, 35, "Modify", "Approve and Release"));
//set result to the tallyResults Vector.
result= tallyResults