There are two ways to deal with this problem, and each has their drawbacks, so you will have to decide which you want to use:
1. Create an approval task with a parallel marker like this:
processWithParallelApproval.png (8.13 KiB) Viewed 10121 times
Set the variable for the parallel approval task to be: @@approversList
Your "Approval" dropdown in the grid needs to have the IDs of the users as the keys of each option. You can do this by creating a group named "Approvers" whose members are the users who can do the approval.
Then, set the "Approval" dropdown to use a
datasource which is an
array variable and set its variable to be
@@availableApproversList
Then create the following trigger to populate the list of options in the "Approval" dropdown:
Code: Select all$groupName = "Approvers";
$groupId = PMFGetGroupUID($groupName);
if (empty($groupId)) {
throw new Exception("Group '$groupName' doesn't exist.");
}
$aUsers = PMFGetGroupUsers($groupId);
@=availableApproversList = array();
foreach ($aUsers as $aUser) {
$fullName = $aUser['USR_FIRSTNAME'] .' '. $aUser['USR_LASTNAME'];
@=availableApproversList[] = array($aUser['USR_UID'], $fullName);
}
Set this trigger to execute before the Dynaform holding the grid.
Then, create a second trigger to set the @@approversList variable:
Code: Select allif (!isset(@=itemsToApprove or empty(@=itemsToApprove)) {
throw new Exception("User didn't fill the itemsToApprove grid");
}
@=approversList = array();
foreach (@=itemsToApprove as $aItem) {
@=approversList[] = $aItem['approval']; //this should be the ID of the user
}
@=approversList = array_unique(@=approversList);
Set this trigger to execute
before assignment in Task 1.
The drawback with this method is that ProcessMaker doesn't create different variables for each user assigned to the parallel task. This means that each user assigned to the parallel task will overwrite the variables set by the previous user.
For a way around this problem, see the trigger code in the attached process in this post:
viewtopic.php?f=41&t=710262&p=789936#p789936
2. The second way to do this is to create multiple approval tasks. The idea is explained here:
http://wiki.processmaker.com/3.0/Trigge ... llel_Tasks
Each parallel approval task will use Value Based Assignment with a different variable:
@@userForApproval1, @@userForApproval2, @@userForApproval3, @@userForApproval4. etc.
The following trigger can be used before assignment in Task 1:
Code: Select allif (!isset(@=itemsToApprove or empty(@=itemsToApprove)) {
throw new Exception("User didn't fill the itemsToApprove grid");
}
$aApprovers = array();
foreach (@=itemsToApprove as $aItem) {
$aApprovers[] = $aItem['approval']; //this should be the ID of the user
}
$aApprovers = array_unique($aApprovers);
@%numberApprovers = count($aApprovers);
$aVars = array(); //variables to save to case
//create a different variable for the assignment of the user and a different grid variable for each parallel task:
for ($i = 0; $i < @%numberApprovers; $i++) {
$varName = 'userForTask' . ($i+1);
$aVars[ $varName ] = $aApprovers[$i];
//new itemstoApproveX for each parallel task:
$gridName = 'itemsToApprove' . ($i + 1);
$itemsToApproveX = array();
//only include the rows in the grid for single approver:
$rowNo = 1;
foreach (@=itemsToApprove as $aItem) {
if ($aItem['approval'] == $aApprovers[$i]) {
$itemsToApproveX[ $rowNo ] = $aItem;
$rowNo++;
}
}
$aVars[ $gridName ] = $itemsToApproveX;
}
//save variables to case:
PMFSendVariables(@@APPLICATION, $aVars);
Set this trigger to fire before assignment in Task 1.
You will have to create separate dynaforms for each parallel approval task with a grid whose variable is named:
itemsToApprove1, itemsToApprove2, itemsToApprove3, itemsToApprove4, etc.
In the task afterwards, you will probably want to create another trigger that will integrate all the grids into 1 grid, like this:
Code: Select all@=completeItemsToApprove = array();
$oCase = new Cases(@@APPLICATION);
$aCaseVars = $oCase->LoadCase(@APPLICATION)['APP_DATA'];
$rowNo = 1;
for ($i = 1; $i <= @%numberApprovers; $i) {
$gridName = 'itemsToApprove' . $i;
foreach ($aCaseVars[ $gridName ] as $aRow) {
@=completeItemsToApprove[ $rowNo ] = $aRow;
$rowNo++;
}
}
Then use "completeItemsToApprove" as the variable for the final grid to show all the approved Items in the final task.