Manual assignment of a task with loop back to the same task

From pmusers
Jump to: navigation, search

The following example shows how to manually assign a user to a task, but if the process loops back to that same task, then reassign the task to the same user who was manually selected to work on it.

Process: Manual_assignment_with_a_Value_Based_Assignment_task-1.pmx (right click and select Save Link As)
Author: Amos Batto (amos[at]processmaker[dot]com)
Version: 1.0 (2019-03-08)
Tested In: PM 3.3.4 Enterprise in Debian 9.5 with PHP 5.6.37

The following process is used to create and execute a work plan in a company:


In the first task "Create Work Plan," a manager will create a work plan and manually select in a dropdown box the employee who will be assigned to the next task which is "Do Work". After that employee completes the "Do Work" task, then the manager will review the work. If the manager decides that the work is "satisifactory", then the process will advance to the "Finalize Work" task. If the manager decides that more work needs to be done, then the process will loop back to the "Do Work" and be assigned to the same employee who was previously selected to do the work.

The "Create Work Plan" tasks contains the following Dynaform to define the work and select the user to assign to the "Do Work" task:


In the properties of the "employeeToDoWork" dropdown, where the manager manually selects the employee to assign to the next task, the datasource property is set to "array variable" and the data variable property is set to: @@availableEmployees

Then, in the Assignment Rules of the "Do Work" task, it is set to Value Based Assignment and its variable is set to: @@employeeToDoWork


Finally, the following trigger is created to get the list of users which are assigned to the "Do Work" task, so that they can be displayed in the "employeeToDoWork" dropdown box:

//set to the ID of the "Do Work" task:
$taskId = '4919684855c81e4eb35de18098073560'; 
@=availableEmployees = array();

$d = new Derivation();
$aAssigned = $d->getAllUsersFromAnyTask($taskId);

foreach($aAssigned as $userId) {
	$aUser = userInfo($userId);
	@=availableEmployees[] = array(
		$aUser['firstname'].' '.$aUser['lastname'].' ('.$aUser['username'].')'

This trigger uses the Derivation::getAllUsersFromAnyTask() function to obtain the list of users assigned to the "Do Work" task.

Set this trigger to fire before the above "Work Plan" Dynaform, so that the "employeeToDoWork" dropdown will be populated.

When the manager starts a case in this process, she will be able select the employee to assign to do the work in the case's first task:


Then, that same user will be assigned to the "Do Work" task: