Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.

Moderator: amosbatto

Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
#823231
I have a parent process, where userA created a case, then it gets assigned to userB, then the process generates a subprocess case. The subprocess case gets assigned to userC.

When userA and userB look in their participated case folder, they should see the parent case AND the child case as well.

What's the cleanest approach to this?

I was thinking of adding userA and userB to the app_delegation table, that way it shows them as participants as well as allow them to add case notes. Or perhaps in the childcase, assign the task to userA, then use PMFDerivateCase to assign another task to userB, and then PMFDerivateCase to userC as originally intended.
Last edited by richvle on Wed Mar 13, 2019 5:49 pm, edited 1 time in total.
#823255
Add the users who need to be able to see the case under Home > Participate to the Ad Hoc assignment list of the task. Assign them individually. Don't assignment them using groups. (This makes the code simpler.)

Then create the following trigger:
Code: Select all
$originalUserId = @@USER_LOGGED;
$taskId = @@TASK;
$index = @%INDEX;
$c = new Cases();

//TU_TYPE=2 means Ad Hoc assignment and TU_RELATION=1 means that assigned individually and not through groups
 $sql = "SELECT * FROM TASK_USER WHERE TAS_UID='$taskId' AND TU_TYPE=2 AND TU_RELATION=1";
$aUsers = executeQuery($sql);
if (empty($aUsers)) {
   throw new Exception("There are no Ad Hoc users for task $taskId");
}
$c->reassignCase(@@APPLICATION, $index, $originalUserId, $aUsers[1]['USR_UID']);
$c->reassignCase(@@APPLICATION, $index+1, $aUsers[1]['USR_UID'], $originalUserId);
$_SESSION['INDEX'] = $index+2;
$_SESSION['USER_LOGGED'] = $originalUserId;
#823269
Thank you for the reply Amos. Since UserA can be anybody from the group called ActiveUsers (dynamically maintained by a separate system), essentially any user can see the case. However, if the app_delegation table doesn't list that user, they shouldn't be able to access it. So adding them ad hoc individually instead of by group, presents a different problem.
#823291
OK, the workaround is to do Ad Hoc assignment of your ActiveUsers group to a task in your subprocess. Also make sure that your User C who is assigned to that task in the subprocess has the PM_REASSIGNCASE permission in her role.

Then add this trigger to your subprocess:
Code: Select all
$task1Id = 'XXXXXXXXXXXXXXXXXXXXX'; //set to ID of task 1 in parent process 
$task2Id = 'XXXXXXXXXXXXXXXXXXXXX'; //set to ID of task 2 in parent process

//look up the users who were assigned to task 1 and task 2 in parent case:
$subcaseId = @@APPLICATION; 

$sql1 = "SELECT AD.USR_UID FROM APP_DELEGATION AD, SUB_APPLICATION SA 
   WHERE SA.APP_UID='$subcaseId' AND SA.APP_PARENT=AD.APP_UID AND AD.TAS_UID='$task1Id'";
$result1 = executeQuery($sql1);
$task1UserId = $result1[1]['USR_UID'];

$sql2 = "SELECT AD.USR_UID FROM APP_DELEGATION AD, SUB_APPLICATION SA 
   WHERE SA.APP_UID='$subcaseId' AND SA.APP_PARENT=AD.APP_UID AND AD.TAS_UID='$task2Id'";
$result2 = executeQuery($sql2);
$task2UserId = $result2[1]['USR_UID'];

$subcaseUserId = @@USER_LOGGED;
$subcaseTaskId = @@TASK;
$index = @%INDEX;

$c = new Cases();
$c->reassignCase(@@APPLICATION, $index, $subcaseUserId, $task1UserId);
$c->reassignCase(@@APPLICATION, $index+1, $task1UserId, $task2UserId);
$c->reassignCase(@@APPLICATION, $index+2, $task2UserId, $subcaseUserId);

$_SESSION['INDEX'] = $index+3;
$_SESSION['USER_LOGGED'] = $subcaseUserId;

Set this trigger to fire in the task of your subprocess.

See: https://wiki.processmaker.com/3.0/Inter ... Case.28.29

PS: I wrote this trigger off the top of my head so it might require debug, but it gives you an idea how to do it.
#823353
Without giving the reassign permission to UserC, I was considering assigning the task to ADMIN (who has the reassign permission), and then when they execute the your trigger, it will reassign to UserA, then reassign to UserB, then reassign to UserC sequentially.

However, to get the trigger to execute, at a minimum, the ADMIN user will have to open or claim the case first. Is there a way to have the trigger execute automatically without having a user open the case?
#823363
You can put the trigger after routing in the task before the subprocess in the master process.
Here is an example:
(19.64 KiB) Downloaded 17 times
(38.11 KiB) Downloaded 18 times


Remember that all the users assigned to tasks in the master process need to be assigned Ad Hoc to the first task in the subprocess.
#823372
Thanks Amos. I was able to use your trigger exactly as is, and it works just fine.
In my particular situation, the Parent Process uses a parallel gateway, then splits to script tasks and multiple subprocesses, so I was unable to set the trigger to execute after routing (of the previous task, since it was a script task). However, I just added the trigger to another script task that executes after the Subprocess is created (1 for each, called "Add Participants To ..... Case"), and it's doing exactly what I wanted, and allows userA and userB to see it in their participated list.
Capture2.JPG
Capture2.JPG (43.95 KiB) Viewed 930 times
amosbatto wrote: Wed Mar 13, 2019 4:55 pm I wrote up some documentation to explain this:
https://www.pmusers.com/index.php/Inclu ... ated_cases
#824102
Upon further testing and reviewing the code, it looks like it a very weird duplication issue when dealing with multiple subprocesses. It ended up adding all involved users into 1 of the process and none to the other (except for the subprocess case assignee). I embedded your trigger into the 2 script tasks as shown.

I think this block of code assumes that it's only 1 subprocess. Perhaps this portion of the code needs to be incorporated into a for loop.
Code: Select all
$subcaseId = $aResult[1]['APP_UID'];
$subcaseUserId = $aResult[1]['USR_UID'];
$subcaseIndex = 1;
Capture3.JPG
Capture3.JPG (121.66 KiB) Viewed 834 times
#824111
If you are going to have two subprocesses then you need to change your trigger code from:
Code: Select all
//look up the new subprocess case in the database:
$parentCaseId = @@APPLICATION;
$sql = "SELECT SA.APP_UID, AD.USR_UID, AD.TAS_UID FROM SUB_APPLICATION SA, APP_DELEGATION AD 
   WHERE SA.APP_PARENT='$parentCaseId' AND SA.APP_UID=AD.APP_UID AND AD.DEL_INDEX=1";
to:
Code: Select all
//look up the new subprocess case in the database:
$subprocessId = 'XXXXXXXXXXXXXXXXXXXXXXXXXXX'; //set to ID of process in subprocess
$parentCaseId = @@APPLICATION;
$sql = "SELECT SA.APP_UID, AD.USR_UID, AD.TAS_UID FROM SUB_APPLICATION SA, APP_DELEGATION AD 
   WHERE SA.APP_PARENT='$parentCaseId' AND SA.APP_UID=AD.APP_UID AND AD.DEL_INDEX=1 AND 
   AD.PRO_UID='subprocessId'";
By the way, using script tasks after the subprocesses to assign the users will only work if your subprocesses are asynchronous. If it is synchronous, that won't work, because the subprocess cases will already be closed. If you want to have synchronous subprocesses, then the only solution is to move the triggers to temporarily reassign users from the parent process to the subprocess and change your SQL query.
#824124
Hi Amos,
Thank you for the code. I just had to change 1 thing. The $subprocessId was missing the '$'. Thank you!
Code: Select all
//look up the new subprocess case in the database:
$subprocessId = 'XXXXXXXXXXXXXXXXXXXXXXXXXXX'; //set to ID of process in subprocess
$parentCaseId = @@APPLICATION;
$sql = "SELECT SA.APP_UID, AD.USR_UID, AD.TAS_UID FROM SUB_APPLICATION SA, APP_DELEGATION AD 
   WHERE SA.APP_PARENT='$parentCaseId' AND SA.APP_UID=AD.APP_UID AND AD.DEL_INDEX=1 AND 
   AD.PRO_UID='$subprocessId'";
View Dynaform in HTML Page

You might also want to check the [url=https://wiki[…]

You are going to have to put the configuration in […]

Hola, hay alguna forma de hacer que estos log se […]

Yo trabajo con la versión PM 3.2.3 - Ente[…]