Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
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.
#817426
Hi,

There are several ways you can do this.

First, is it absolutely necessary for the first process to reach the end event? The easiest way to do what you're asking is to add the 2nd process to the 1st process using a sub-process right before the end event. That way, when the sub-process is completed, the only thing left in the first process is the end event. (https://wiki.processmaker.com/3.2/Sub-Processes)

Another possible solution is to use message events. The end event in the first process would be an end message event and the start event of the second process would be a start message event. (https://wiki.processmaker.com/3.2/Events)

The third possible solution would be to use a trigger before the end event in the first process to call the New Case endpoint to start a new case of the other process. (https://wiki.processmaker.com/3.2/REST_ ... T_.2Fcases

I hope one of these solutions work out for you.
#817440
Hi!

Thanks a lot for your suggestions. I tried to use your this suggestion which is under.
skbecker wrote: Wed Oct 17, 2018 9:19 am
The third possible solution would be to use a trigger before the end event in the first process to call the New Case endpoint to start a new case of the other process. (https://wiki.processmaker.com/3.2/REST_ ... T_.2Fcases
But I have accrosed a new problem and I added it on with processes and a picture of error.
Attachments
Ekran Alıntısı.PNG
Ekran Alıntısı.PNG (29.39 KiB) Viewed 9438 times
(23.35 KiB) Downloaded 299 times
(22.68 KiB) Downloaded 394 times
#817458
Hi,

I took a look at the trigger you used in your process. The first part of the trigger works fine, and I was able to start new cases of process 2 multiple times. However, there is a problem with a particular line of code in the trigger that displays a message after creating the new case with a trigger (at least in my case). The good news is that you only need the first part of the trigger to create a new case of process 2:

$processId = '7769165035bc828d38577a6093359488'; //set to the Process ID
$dummyTaskId = '8042602535bc8292d4da584026747447'; //set to ID of dummy task
@@newCaseId = PMFNewCase($processId, @@USER_LOGGED, $dummyTaskId,
array('selfServiceAssignee' => @=selfServiceAssignee));

The rest of the code doesn't really matter unless you want to display a message on a routing screen depending on whether there was an error, or if a user or group is assigned to the first task of the next process.

However, in your case it looks like the first part of the trigger didn't work for you. First of all, double check the process and task ID to make sure they're correct. The process ID should be the ID of process 2 and the task ID should be the task ID of the first task in process 2. If that doesn't solve your problem, try assigning the user who completes process 1 to the task in process 2. The same user who completes process 1 is going to be assigned to process 2. Let me know if that solves your problems.
#817467
Thanks for your attention.

I solved my problem thanks to your solution. Now I have one more problem which is big for me again.

My problem is I have two cases and one of them is unnecessary and I need to delete it. I added a picture about it.

What can I do to solve this problem?

Can you help me?

Kr.
Attachments
aynı.PNG
aynı.PNG (35.53 KiB) Viewed 9361 times
#817477
Hi!

Actually your solution is not what I want. I added a sample like my process. It is a sample because my process is complicated a bit.

But I need to explain how will you use it.

After starting the case, you need to click submit and than you should open and click Task1(Task2 is available in your inbox as well) because of to see my problem. And than when you click submit Task1 in inbox, you will see two Task2 in your inbox. I want to delete one of them by coding because if when I open one of them, I see all data in one task thanks to get my data from database. When the completed this task, the other task doesn't have any data. So I don't want to see it anymore because of to complete my process.

I tried to explain my question in a detail way. I hope I am successful to expain it.

And I added a video. I hope it helps you

Thanks a lot
Kr.
Attachments
(720.51 KiB) Downloaded 306 times
(40.36 KiB) Downloaded 298 times
#817500
Hi!

I tried that your suggestion but it doesn't work as I want. When I used it, It delete all of cases butI want to delete only one of two cases.

I added a sample process which I implemented like you said and It delete all of the cases.

I hope I could explain my problem in a detail way now.
Kr.
Attachments
(41.54 KiB) Downloaded 328 times
#817531
Hi processmakerlover, I watched your video. You are not creating multiple cases, so you don't want to use Cases::removeCase(). What you are doing is creating is multiple parallel tasks in a single case.

You need to use PMFDerivateCase() to automatically route on the other open parallel task of your case.

I have created a programming example for you:
https://www.pmusers.com/index.php/Routi ... llel_tasks
#817536
Hi Amos!

Actually my problem is not that you think.

I want to tell you what I want to in this process.

I attached a picture, the video and our process, in the picture you can see two cases and they are the same case number and case id in the same task. I can't delete one of them because of to have the same case id. Why do I want to delete one of them? Because, thanks to have the same case id, my all data that I get from database, when I open a case, I see all data in this case. And if I submit this case, all data send and so the other case become empty(because I sent all data and my users want to see data to complete this case). So I can't complete my process because of the empty case.

I want to delete this case by using trigger.

Thanks for your attention.
Kind regards
Attachments
(720.51 KiB) Downloaded 287 times
(40.36 KiB) Downloaded 290 times
1.PNG
1.PNG (83.12 KiB) Viewed 8461 times
#817555
Your process is creating multiple threads in the same case. There is no function in ProcessMaker to cancel a thread in a trigger. If you want an extra thread to end, you need to create a process where the extra thread will end by encountering a converging gateway (which merges multiple threads into one), but that won't work when you have loopbacks that can create more and more threads.

Can you design your process without loopbacks which add additional threads to the case?

If you really can't design your process without loopbacks to add additional threads, then there is a quick and dirty way to end threads by writing directly to the APP_DELEGATION table and changing DEL_THREAD_STATUS to 'CLOSED' and setting a datetime in DEL_FINISH_DATE. This is definitely not the recommended way to do it, so use at your own risk.

In order to be able to write to the APP_DELEGATION table in a trigger, you will need to edit your workflow/engine/config/execute-query-blacklist.ini and change the line from:
queries="INSERT|UPDATE|REPLACE|DELETE"
To:
queries = "INSERT|REPLACE|DELETE"

Here is some sample trigger code to cancel all other open threads in the current case:
Code: Select all
//look up the thread index for the current task:
$caseId = @@APPLICATION;
$index = @@INDEX;
$sql = "SELECT * FROM APP_DELEGATION WHERE APP_UID='$caseId' AND DEL_INDEX=$index";
$aCurrentTask = executeQuery($sql);
$currentThread = $aCurrentTask[1]['DEL_THREAD']; 

//get all the open tasks not in the current thread and cancel them.
$sql = "SELECT * FROM APP_DELEGATION WHERE APP_UID='$caseId' AND DEL_THREAD_STATUS='OPEN' 
     AND DEL_THREAD<>$currentThread";
$aTasksToClose = executeQuery($sql);

foreach ($aTasksToClose as $aTask) {
     $now = date('Y-m-d H:i:s');
     $sqlCancelTask = "UPDATE APP_DELEGATION SET DEL_THREAD_STATUS='CLOSED', DEL_FINISH_DATE='$now' 
          WHERE APP_UID='$caseId' AND DEL_INDEX=" . $aTask['DEL_INDEX'];
     executeQuery($sqlCancelTask);
}
Note: this code will cause the case count to be incorrect for users if using the Enterprise Edition, so only recommended for the Community Edition.

I have changed your process to use this trigger code in Task 3:
(51.9 KiB) Downloaded 340 times
#817563
Hi Amos,

Can you design your process without loopbacks which add additional threads to the case?
I can't really design my process without loopback.

I tried your process and it is really great but there is one simple problem for me. I want to delete the case not open the other case of next task(task3). I want to delete it after sending a case in task2.

I want to delete(complete) after sending(submit) case because if it deletes(completes) after opening case in task3, until open the case in task3, maybe can drop new case with the same case id and case number thanks to look(in my real process cases come from loop in this process there isn't any problem like it) so the new case delete with the data.

Is there any way to delete(completes) the case after submit the case in task2 ?

Or maybe new method can solve my problem. For this process, If I sent several cases to task2 from task1, normally there are several cases but can I see only one case with all data of several cases.

Thanks for your helping
Best regard
#817578
processmakerlover wrote:I tried your process and it is really great but there is one simple problem for me. I want to delete the case not open the other case of next task(task3). I want to delete it after sending a case in task2.
You can set the trigger to close all the other open threads in task2. You don't need to create a task3.
processmakerlover wrote:I want to delete(complete) after sending(submit) case because if it deletes(completes) after opening case in task3, until open the case in task3, maybe can drop new case with the same case id and case number thanks to look(in my real process cases come from loop in this process there isn't any problem like it) so the new case delete with the data.
Your English is not very clear, so I'm not sure what you are trying to do.

You can only delete a case when it is in the starting task (either with the menu Action > Delete or PMFDeleteCase() in a trigger), meaning that the case is removed from the database and there will be no record of it. After the first task in the case, you can only cancel the case (either with the menu Action > Cancel or PMFCancelCase() in a trigger), meaning that the case stays in the database, but it no longer appears in the list under Home > Inbox and Home > Drafts, but it is still listed as read-only under Home > Participated and Home > Advanced Search.

Canceling a case will prevent all open tasks from being routed to the next task, but you need to specify the delegation index for each open task to remove them from the lists under Home > Inbox and Home > Draft. In your example, you have two open threads, so you need to cancel both of them like this:
Code: Select all
//cancel the current task:
PMFCancelCase(@@APPLICATION, @%INDEX);
//cancel the open task in the case's other thread:
$sql = "SELECT * FROM APP_DELEGATION WHERE APP_UID='$caseId' AND DEL_THREAD_STATUS='OPEN' 
     AND DEL_INDEX<>".@@INDEX;
$aTasks = executeQuery($sql);

foreach ($aTasks as $aTask) {
   PMFCancelCase(@@APPLICATION, $aTask['DEL_INDEX']);
}

//redirect to the case list and die:
header("location: casesListExtJsRedirector");
die();
You can't use the same case number in multiple cases, but you can have the same case with multiple threads.

A 1xbet clone script is a pre-designed software so[…]

4rabet clone script is enabling entrepreneurs to e[…]

Parimatch clone script is enabling entrepreneurs t[…]

In the world of cryptocurrency, a wallet is an app[…]