To populate the report, you need another BPM Events rule that captures the event reporting the priority level in each event-map, and counts the events for each level of priority. This informs you how many task assignments take place. The events you need to capture are of the following form:
In particular, for each instance of the "Assign_A_Task_V2" process, you must capture the following data:
The priority of the task. For this, you must catch the W_COMPLETED event of the Start workstep, revealing the priority level of the task.
The completion time of the DoTask workstep (the task duration). This is the elapsed time between the W_ACTIVATED event and W_COMPLETED event of the DoTask process.
Use the data above to capture the following events:
Note: Instead of using W_ACTIVATED of "Do Task," here we use W_COMPLETED of "Start," which is already caught in order to get the priority. There is no significant elapsed time between these two events. As a general guideline, the smaller the number of events a rule correlates, the faster it executes.
You can write a rule that correlates these two events and updates the corresponding report attributes (including count and average duration) for this priority level. Here is the definition of the rule "update_myTaskReport" that builds the report:
rule update_MyTaskReport
activated by
EVT_1 of
BP Server::W_COMPLETED{WORKSTEPNAME:"Start",PROCESSTEMPLATENAME:"Assign_A_Task_V2"},
EVT_2 of BP Server::W_COMPLETED{WORKSTEPNAME:"DoTask",PROCESSTEMPLATENAME:"Assign_A_Task_V2"}
correlated with INDEX
then{
val vcell = Assign_A_Task_V2::Assign_A_Task_V2_data::
MyTaskReport_V2[EVT_1.context.TaskPriority][1];
vcell.comptime ::= avg(duration(EVT_1.date , EVT_2.date)/1000,
vcell.count++, 1);
discard(EVT_1);
discard(EVT_2);
The rule "update_myTaskReport" uses two event variables: EVT_1 and EVT_2, both of profile BP Server::W_COMPLETED. This means these events are generated by BP Server (event type:BP Server), at the completion of some workstep (event value: W_COMPLETED). Additional conditions further select the right events for the rule: they must be related to the completion of the "Start" workstep and of the "DoTask" workstep of the "Assign_A_Task_V2" process.
Since there are multiple process instances, we want to make sure that the two events (one signaling the "completion of the Start workstep" and another signaling the "completion of the DoTask workstep") belong to the same process instance. The clause: correlated with INDEX enforces this, as there is an index created automatically by the rule engine for all BP Server events, based on their process ID. The statement indicates that these events are correlated based on the same index entry (here, PID).
The rule "update_myTaskReport" therefore reads:
"Each time a task assignment process instance generates the pair of events (end Start workstep, end DoTask workstep), then increment the report cell that corresponds to its priority, and also update the average completion time for this level of priority."
Note: The rule is executed only when the last event of the pair is generated, that is at the end of the "DoTask" workstep.
Each time a combination of two events is generated that satisfies this rule, the monitor action executes and modifies the element (cell) of the report that corresponds to the level of priority given by the first event EVT_1. This modification concerns the two attributes (slots) defined for each cell of this report. It performs the following operations:
1. Update the average value for completion time (comptime).
2. Increment the implicit count of the report cell.
The elapsed time between the beginning and the end of a task is obtained by the function duration(), the first argument of which specifies the desired time unit (here, seconds). The avg() function calculates the new average, using the new value (duration), and the default count, the value of which is incremented automatically (++ operator).
Because there is only one such pair of events generated each time a new task is assigned, the rule "update_myTaskReport" and its monitoring action is triggered only once for each instance of the "Assign_A_Task_V2" process. The action of the rule consists of an infopad operation, which increments the report element that corresponds to the level of priority recorded in the event data.