Routing parallel tasks

From pmusers
Jump to: navigation, search

This programming example shows how to automatically route on all the other open parallel tasks in the current case.

Process: Route_other_parallel_tasks-1.pmx (right click and select Save link as)
Author: Amos Batto (
Created: 2018-10-29 (version 1)
Tested in: PM 3.2.3 Community in Debian 9.5 with PHP 5.6.37

Create the following process for employees to request a resource:


Any one of three managers may decide whether to approve, reject or require a revision of the request. Once one manager makes a decision, the other open "ManagerX Decision" tasks will automatically be routed on, so only one of the parallel tasks in the current case will need to manually completed by a manager.

Then, create a Dynaform for an employee to fill out a "Request Resource" form:


Set this DynaForm to be a step in the "Request Resource" task, which is the first task in the process.

Then, create another Dynaform for the managers to enter their decision:


Set this DynaForm to be a step in each of the "ManagerX Decision" tasks.

Then, add the following trigger to automatically route on any other open parallel tasks in the current case:

if (!empty(@@managerDecision)) {
   $caseId = @@APPLICATION;
   $userLogged = @@USER_LOGGED;
   $index = @%INDEX;
   //Select all the other parallel tasks for the current case that are still open
   $threads = executeQuery($query);
   //if there are any open parallel tasks, then automatically route them:
   if (is_array($threads) and count($threads) > 0) {

      //PMFCancelCase can change the session variables, so save them and restore them afterwards.
      $g = new G();
      @=cancelResults = array();

      //route on the other open parallel tasks
      foreach ($threads as $aThread) {
         @=cancelResults[] = PMFDerivateCase($caseId, $aThread['DEL_INDEX'], false, $aThread['USR_UID']);


This trigger code queries the APP_CACHE_VIEW table in the database for open parallel cases in the current case. If it finds any, then it calls G::sessionVarSave() to save the current session variables. This is necessary, because PMFDerivateCase() will reset the session variables to another case ID, logged user ID and delegation index. so the original session variables need to be saved.

Then, PMFDerivateCase() is called for each parallel task (which isn't the current task) to automatically route it on, so that its assigned user doesn't have to work on the task. After routing on the other parallel tasks, then G::sessionVarRestore() is called to restore the session variables to their original values. If this isn't called, then the logged-in user or the current task could change and the user wouldn't be able finish the current task correctly.

Set this trigger to fire before assignment in each of the "ManagerX Decision" tasks. Do NOT set it to fire before or after routing, since that would create an infinite loop in the process.

When an employee creates a new case in this case, the employee will fill out a request for a new resource:


Then the case will route to three different managers who are assigned to the "ManagerX Decision" tasks.


One of the managers will open the case and fill out the "Resource Decision Form":


Then, the case will continue to the "Allocate Resource" task if the manager selected "Approve" in the Manager's Decision" field. If "Reject" was selected, then the case will terminate. If "Revise Request" was selected, then the case will be routed back to the first task and assigned to the original user who filled out the request, so he/she can edit the request and resubmit it or cancel it.