Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
By Ryguy2
#824140
Hello,
I have a trigger that is setup to pause the case until a certain time. During my testing this was working, but now it doesn't appear to be working properly.
Code: Select all
//get the user assigned to the next task:
$c = new Cases();
$aCaseInfo = $c->LoadCase(@@APPLICATION, @%INDEX+1);
//if next task is a subprocess then no assigned user:
if (empty($aCaseInfo['CURRENT_USER_UID']))
    $userId = @@USER_LOGGED;
else
    $userId = $aCaseInfo['CURRENT_USER_UID'];

PMFPauseCase(@@APPLICATION, @%INDEX+1, $userId, @@course_end);
I also have a follow up trigger that will send and email when unpaused. I know that part works.
Not sure If I need another Trigger somewhere or if there is something that should be modified for the unpause.

Thank you in advance.
#824147
If you are executing this with a cron script or in a script task, then the @%INDEX will be set to its value the last time a user manually worked on the case, so it may not be accurate.

Also, if you have multiple branches in your process, then you can't rely on @%INDEX+1 being the next task in the process, because it might be a task in the other branch of the process.

I recommend querying to APP_CACHE_VIEW table to make sure that you are getting the correct INDEX and userID:
Code: Select all
//lookup user ID and del_index for the next task:
$caseId = @@APPLICATION;  
$nextTaskID = '1234567890abcdef1234567890abcdef'; //set to ID of the next task 

$sql = "SELECT USR_UID, DEL_INDEX FROM APP_CACHE_VIEW WHERE APP_UID='$caseId' AND
   TAS_UID='$nextTaskId' AND DEL_THREAD_STATUS='OPEN'";
$result = executeQuery($sql);

If (empty(result)) {
  throw new Exception("Bad query o no DB record: ".$sql);
}  

PMFPauseCase(@@APPLICATION, $result[1]['DEL_INDEX'], $result[1]['USR_UID'], @@course_end);
By Ryguy2
#824163
Ok,

I Think I am following you a bit here.
When I was testing this seemed to work without fail though. I have the user assigned to the case just paused. We are running a cron job to handle this. Is there a better way to handle this in the system? I have an email trigger that gets sent once the case unpauses. (I have tested that so I know that will fire once I unpause).

Just trying to keep things simple in the process.

Thank you
By Ryguy2
#824164
I am looking through this from the Database side. Will the TAS_UID Always be the same for this step?
Also, as I am looking at the select statement DEL_THREAD_STATUS='OPEN', when I am looking a record that should have unpaused the STATUS is set to 'CLOSED'. The APP_THREAD_STATUS='OPEN' I am looking at the app_cache_view table.

Thank you
By Ryguy2
#824165
So, I have been looking at the process this morning. I have found that in the app_delay table the records are showing a proper date for the APP_DISABLE_ACTION_DATE but the task is still in a paused state. Would this have something to do with Cron? or is it possible that I am missing a UNPAUSE trigger that needs to fire?

If I manually unpause my email fires and the process moves back to the inbox as well.

Thank you in advance..
#824167
The TAS_UID (which is the ID of the task) is fixed. You can find it by turning on Debug Mode and then looking at the TASK system variable while running a case. The Task ID will only change if you export the process and when you import the process, you select the option to change the UID.

You are right, when a case is paused, the DEL_THREAD_STATUS='CLOSED'.

Try this code:
Code: Select all
//lookup user ID and del_index for the paused task:
$caseId = @@APPLICATION;  
$nextTaskID = '1234567890abcdef1234567890abcdef'; //set to ID of the next task 

$sql = "SELECT ACV.USR_UID, ACV.DEL_INDEX FROM APP_CACHE_VIEW AS ACV, APP_DELAY AS AD
    WHERE ACV.APP_UID='$caseId' AND ACV.TAS_UID='$nextTaskId' AND ACV.DEL_THREAD_STATUS='CLOSED'
    AND ACV.DEL_INDEX=AD.APP_DEL_INDEX AND AD.APP_TYPE='PAUSE' AND    
    AD.APP_DISABLE_ACTION_USER='0' AND AD.APP_AUTOMATIC_DISABLED_DATE IS NULL ";
$result = executeQuery($sql);

If (empty(result)) {
  throw new Exception("Bad query or no DB record: ".$sql);
}  

PMFPauseCase(@@APPLICATION, $result[1]['DEL_INDEX'], $result[1]['USR_UID'], @@course_end);
By Ryguy2
#824233
Ok,

So we tried this:
Code: Select all
//lookup user ID and del_index for the paused task:
$caseId = @@APPLICATION;  
$nextTaskID = '1234567890Isetthistothecorrect1234567890abcdef'; //set to ID of the next task 

$sql = "SELECT ACV.USR_UID, ACV.DEL_INDEX FROM APP_CACHE_VIEW AS ACV, APP_DELAY AS AD
    WHERE ACV.APP_UID='$caseId' AND ACV.TAS_UID='$nextTaskId' AND ACV.DEL_THREAD_STATUS='CLOSED'
    AND ACV.DEL_INDEX=AD.APP_DEL_INDEX AND AD.APP_TYPE='PAUSE' AND AD.APP_UID=ACV.APP_UID AND    
    AD.APP_DISABLE_ACTION_USER='0' AND AD.APP_AUTOMATIC_DISABLED_DATE IS NULL ";
$result = executeQuery($sql);

If (empty(result)) {
  throw new Exception("Bad query or no DB record: ".$sql);
}  

PMFPauseCase(@@APPLICATION, $result[1]['DEL_INDEX'], $result[1]['USR_UID'], @@course_end);
We hard coded the CASE ID in, I also have the TaskID set correctly in my step(remarked out for post) and we ADDED this as well: AD.APP_UID=ACV.APP_UID AND
It still isn't unpausing the task.
When we run it as a query we get the result returned, it just isn't unpausing the case. We manually ran our Cron job.
Any other suggestions? Seems like we are very close.

Thank you for your help.
#824234
Change PMFPauseCase() to PMFUnpauseCase() in your trigger.

Add this code to your trigger to check whether the database query is working:
Code: Select all
$result = executeQuery($sql);
print "\nSQL: $sql\n";
var_dump($result);
die;
If you paused the case and the trigger to unpause it is in the same case, then the trigger can't be executed when the case is paused.
How you are executing this trigger? In a different ProcessMaker case? Web Services? REST from external script?

There are two ways to handle this. You can set the datetime when to unpause when pausing the case, as shown in this example:
https://www.pmusers.com/index.php/Pause ... nt_of_time

Or you can use a separate process which is in charge of unpausing other cases. See this example of a separate process:
https://www.pmusers.com/index.php/Send_ ... is_overdue
(the example is for sending an email, put you can replace that with PMFUnpauseCase(). )
By Ryguy2
#824274
Yes,
I was trying to do the unpause and pause in the same workflow. I will look at these today and create a separate process for the unpause.

I will report back and let you know how it goes or if I have any additional questions.
By Ryguy2
#824281
You are correct I was trying to do a pause and an unpause in the same workflow.

I created a new workflow for unpausing, but I am still having troubles. I did find the Cron was not running properly, but that is resolved.
So, I have 5 jobs that should have been release by now.. For testing purposes, I have put the actual APP_UID in to run for one case, and did not set the dummy task to loop. ( I have removed my$caseId and my$taskId). I placed the task in debug mode and run the task. I also kick of the Cron Manually. I am still not seeing the case unpause. I feel like I am super close when we put this into query we are getting the results that we want.

Any other thoughts?

Thank you kindly

//set to the ID of the task which should send an email when overdue.
//this ID can be found by running a case in Debug Mode and looking at the TASK system variable:

$caseId = @@APPLICATION;
$taskId = 'somenumber';

//Search for cases where the task is overdue:
$now = date("Y-m-d H:i:s");
$sql = "SELECT ACV.USR_UID, ACV.DEL_INDEX FROM APP_CACHE_VIEW AS ACV, APP_DELAY AS AD
WHERE ACV.APP_UID='$caseId' AND ACV.TAS_UID='$nextTaskId' AND ACV.DEL_THREAD_STATUS='CLOSED'
AND ACV.DEL_INDEX=AD.APP_DEL_INDEX AND AD.APP_TYPE='PAUSE' AND AD.APP_UID=ACV.APP_UID AND
AD.APP_DISABLE_ACTION_USER='0' AND AD.APP_AUTOMATIC_DISABLED_DATE IS NULL " AND '$now' > AD.APP_DISABLE_ACTION_DATE;
$result = executeQuery($sql);

If (empty(result)) {
throw new Exception("Bad query or no DB record: ".$sql);
}
PMFunpauseCase(@@APPLICATION, $result[1]['DEL_INDEX'], $result[1]['USR_UID'], @@course_end);
Attachments
testtask.JPG
testtask.JPG (15.06 KiB) Viewed 18790 times
#824297
Your trigger code doesn't know the case ID. You need to find this information by querying the APP_DELAY and APP_CACHE_VIEW tables. I don't have time to explain it right now. I'll try to explain it tomorrow.
By Ryguy2
#824321
This seemed to do the trick. Thank you again for your help.
//set to the ID of the task which should send an email when overdue.
$sql = "SELECT ACV.USR_UID, ACV.DEL_INDEX, ACV.APP_UID FROM APP_CACHE_VIEW AS ACV, APP_DELAY AS AD
WHERE ACV.TAS_UID='123456789123456789' AND ACV.DEL_THREAD_STATUS='CLOSED'
AND ACV.DEL_INDEX=AD.APP_DEL_INDEX AND AD.APP_TYPE='PAUSE' AND AD.APP_UID=ACV.APP_UID AND
AD.APP_DISABLE_ACTION_USER='0' AND AD.APP_AUTOMATIC_DISABLED_DATE IS NULL AND current_date() > AD.APP_DISABLE_ACTION_DATE";
$result = executeQuery($sql);

If (empty(result)) {
throw new Exception("Bad query or no DB record: ".$sql);
}
PMFunpauseCase($result[1]['APP_UID'], $result[1]['DEL_INDEX'], $result[1]['USR_UID']);
By Ryguy2
#824323
So, by setting doing this will the process only release 1 record per pass? or will it release all the records that it finds. That will help me better understand the frequency that I need to set this. Also, once you start a loop process how do you stop it if you no longer need or need to change the process?

Thank you again for your help on this.
#824344
Your code will only unpause the first case that it finds in the database which has passed its unpause date and your trigger will only execute once. What you probably want is to create a loop with an intermediate timer event as shown in the example, so your trigger executes over and over and you probably want to change your trigger code so it will unpause all the cases that have passed their unpause dates.

Why you are trying to program this, when ProcessMaker already provides this functionality?

If you have set your cron.php file to periodically execute on your server, then ProcessMaker will automatically unpause any cases that have passed their unpause date (which is the date that the user sets when pausing the case).
By Ryguy2
#824353
Sorry, I did create it as a loop. Cron was not unpausing the cases at the time interval. I only had a pause built into the original case where the case would pause once it got past approvals and looked at an original date. So your saying that Cron should be unpausing anything that had a past due date because it was paused?
#824369
This trigger code is finding paused cases whose unpause date has been passed:
$sql = "SELECT ACV.USR_UID, ACV.DEL_INDEX, ACV.APP_UID FROM APP_CACHE_VIEW AS ACV, APP_DELAY AS AD
WHERE ACV.TAS_UID='123456789123456789' AND ACV.DEL_INDEX=AD.APP_DEL_INDEX AND
AD.APP_TYPE='PAUSE' AND AD.APP_UID=ACV.APP_UID AND AD.APP_DISABLE_ACTION_USER='0'
AND AD.APP_AUTOMATIC_DISABLED_DATE IS NULL AND current_date() > AD.APP_DISABLE_ACTION_DATE";

This is the same thing as ProcessMaker's cron.php file does when it is executed, so you should let cron.php handle it.

Do you want to do something different?
By Ryguy2
#824380
Yes, I would like Cron to be handle the unpause, however it is not doing the unpause. I am guessing this is due to how we are pausing the case. I am trying to setup a test process to verify that I can get the pause and unpause to work like your example for pmfpausecase.

We had the index +1 in ours. If that does resolve the issue. I will let you know. If cases have been paused that way will we have problems until those cases work their way thru the system?

Thank you
#824389
Ryguy2 wrote:We had the index +1 in ours. If that does resolve the issue. I will let you know. If cases have been paused that way will we have problems until those cases work their way thru the system?
No, it won't cause any problems. If the index number was incorrect, then the case won't be unpaused. If the case unpaused, then the index number you used was correct.

If you used PMFPauseCase() in a trigger to pause the case and didn't set an unpause date, then cron.php won't unpause the case. I have seen Windows installations where the scheduled tasks don't execute correctly, so cron.php never runs. If you are still having problems, then check your SQL query from your code by executing it in MySQL. Using PhpMyAdmin will help you.

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[…]