Routing to self or selected user's manager

From pmusers
Jump to: navigation, search

This example shows how the user can select whether the next task in the process will be assigned to herself or to the manager of a user selected in a dropdown box. Depending on which user is selected, the process will go a different parallel task. Then, the flow will return to the original user.



Process: Route_to_self_or_another_user's_manager-1.pmx (right click and select Save Link As)
Author: Amos Batto <amos[at]processmaker.com>
Version: 1.0 (2019-06-17)
Tested in: PM 3.3.8 Community in Debian 9.5


Create the following process:

RouteToSelfOrManager ProcessInDesigner.png

"Task 1 - User A", "Task 2 - User A" and "Task 3 - User A" will be assigned to the same user who started the case. That same user in the first task will select whether she will assign herself to "Task 2" or to the manager of a user that she selects in a dropdown box.

"Task 2 - User A" and "Task 3 - User A" will use Value Based Assignment and their variable will be: @@assignedUserTask1

RouteToSelfOrManager AssignmentRulesToSelf.png

Make sure that "Task 1 - User A", "Task 2 - User A" and "Task 3 - User A" all have the same list of users in their assignment list.

The "Task 2 - User B's Manager" will also use Value Based Assignment, but its assignment list will contain the managers of users which can be selected in the first task and its variable is: @@selectTask2User

RouteToSelfOrManager Task2AssignmentRules.png

The diverging exclusive gateway will use the following conditions to decide which will be the second task in the process:

RouteToSelfOrManager RoutingRulesGateway.png

Then, create the following "Select Next User" Dynaform:create the following dropdown where the user who starts the case can select which user will be assigned to the second task in the process:

RouteToSelfOrManager SelectNextUserFormInDesigner.png

The dropdown box is associated with the "selectTask2" variable which is also the variable for user assignment in the second task. The datasource property of the dropdown box is set to "array variable" and its data variable property is set to: usersListForTask2

In order to populate the "userListForTask2" variable with a list of users whose managers can be assigned to the second task, first create a group with the title "Task 2 Users" and assign users to that group whose managers can be assigned to the second task.

RouteToSelfOrManager CreateGroup.png

Then, add the following trigger to the process, which will populate the list of users in the "selectTask2User" dropdown whose managers can be assigned to the second task:

//set to name of group containing users, whose managers are assigned to Task 2:
$groupName = 'Task 2 Users'; 
$groupId = PMFGetGroupUID($groupName);

if (empty($groupId)) {
  throw new Exception("Group '$groupName' doesn't exist.");
}

$aUsers = PMFGetGroupUsers($groupId);
@=usersListForTask2 = [
  [ @@USER_LOGGED, '(self)' ]
];

foreach ($aUsers as $aUser) {   	
   $aUserInfo = userInfo($aUser['USR_UID']);
   $fullName = $aUserInfo['firstname'].' '.$aUserInfo['lastname'].
      ' ('.$aUserInfo['username'].')';	
   
   if (empty($aUserInfo['reportsto'])) {
      throw new Exception("User '$fullName' needs to be assigned to a department.");
   }

   @=usersListForTask2[] = array($aUserInfo['reportsto'], $fullName);
}

@@assignedUserTask1 = @@USER_LOGGED;

Set this trigger to fire before the "Select Next User" Dynaform in the first task.

When a case is run in this process, the user who starts the case can select either herself or a user whose manager will be assigned to the second task:

RouteToSelfOrManager SetTriggerBeforeForm.png

In this example, Louis Criscuolo, who is the manager of Melissa Centellas, will be assigned to the second task in the process:

RouteToSelfOrManager SelectNextUserInCase.png