Create a new process which has a single task and a DynaForm. Then create a email template file named "overdueCase.html" with the following content:
Code: Select allDear @#assignedUser,
The following case which is assigned to you is overdue:
Case No: @#caseNo
Case Title: @#caseTitle
Case Status: @#caseStatus
Current Task: @#taskName
When Assigned: @#taskAssigned
When Due: @#taskDue
Case Created By: @#caseCreatedBy
Case Start Date: @#caseStartDate
Case Last Updated: @#caseUpdatedDate
Link: @#caseLink
Please open the case and finish the task.
Then, create the following trigger and set it to fire before the DynaForm:
Code: Select all//find the task ID by running a case in Task_2 and look at the TASK system variable:
$taskId = 'XXXXXXXXXXXXXXXXXXXXXXX';
//set to the same email address used in Admin > Settings > Email Servers:
$emailFrom = 'admin@example.com';
$twoDaysAgo = date('Y-m-d H:i:s', strtotime('-2 days'));
$query= "SELECT * FROM APP_CACHE_VIEW WHERE TAS_UID='$taskId' AND
(APP_STATUS='TO_DO' OR APP_STATUS='DRAFT') AND DEL_THREAD_STATUS='OPEN' AND
DEL_TASK_DUE_DATE < '$twoDaysAgo' ";
$aCases = executeQuery($query);
if (!is_array($aCases)) {
die("Error: Bad Query: $query\n");
}
foreach ($aCases as $aCase) {
$c = new Cases();
$aCaseInfo = $c->loadCase($aCase['APP_UID'], $aCase['DEL_INDEX']);
$aData = array(
'caseNo' => $aCase['APP_NUMBER'],
'caseTitle' => $aCase['APP_TITLE'],
'caseStatus' => '$aCase['APP_STATUS'],
'taskName' => $aCase['APP_TASK_TITLE'],
'taskAssignedDate' => $aCase['DEL_DELEGATE_DATE'],
'taskDueDate' => $aCase['DEL_TASK_DUE_DATE'],
'caseCreatedBy' => $aCaseInfo['CREATOR'],
'caseStartDate' => $aCaseInfo['CREATE_DATE'],
'caseUpdatedDate'=> $aCaseInfo['UPDATE_DATE'],
'caseLink' => (G::is_https() ? "https://" : "http://") . $_SERVER['SERVER_NAME'] .
':' . $_SERVER['SERVER_PORT'] . //comment out if no port number
'/sys'.@#SYS_SYS.'/'.@#SYS_LANG.'/'.@#SYS_SKIN.'/cases/open?APP_UID=' .
$aCase['APP_UID'] . '&DEL_INDEX=' . $aCase['DEL_INDEX'] . '&action=draft'
);
$aUser = userInfo($aCase['USR_UID']);
PMFSendMessage($emailFrom, $aUser['mail'], '', '', 'Overdue case ' . $aCase['APP_TITLE'],
'overdueCase.html', $aData);
}
Run a case in this new process and verify that the trigger code works, but do not complete the case. Get the unique ID of the trigger and turn on the Debugger to get the case's ID found in the APPLICATION system variable. These IDs will be used used in the following script.
Then, go to the server running ProcessMaker and use a plain text editor to create a file named "checkOverdueCases.php" which is located in a place which isn't accessible to the internet. Add the following PHP code to the file:
Code: Select all<?php
$serverAddress = "http://example.com"; //set to the server's address
$workspace = 'workflow'; //set to the workspace which is 'workflow' by default
$user = 'admin'; //set to user who is assigned to a case in the process to run trigger
$password = 'p4sSw0rD'; //set to password of the user
$caseId = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX'; //set to case's ID
$triggerId = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX'; //set to the trigger's ID
ini_set("soap.wsdl_cache_enabled", "0");
ini_set('error_reporting', E_ALL);
ini_set('display_errors', True);
$client = new SoapClient("$serverAddress/sys$workspace/en/neoclassic/services/wsdl2");
$md5Pass = 'md5:' . md5($password);
$params = array(array('userid'=>$user, 'password'=>$md5Pass));
$result = $client->__SoapCall('login', $params);
if ($result->status_code == 0)
$sessionId = $result->message;
else
print "Unable to connect to ProcessMaker.\nError Number: $result->status_code\n" .
"Error Message: $result->message\n";
#look up the caseId and delIndex with the caseList() web service and the triggerIndex in MySQL
$params = array(array(
'sessionId' => $sessionId,
'caseId' => $caseId,
'triggerIndex' => $triggerId,
'delIndex' => '1' //assuming first task in case
));
$result = $client->__SoapCall('executeTrigger', $params);
if ($result->status_code != 0)
print "Error: $result->message \n";
else
print_r($result);
?>
This script uses the
executeTrigger() web service to execute the same trigger code. (You can also use REST, but I recommend using web services because they are simpler and permit any registered user to login.)
After creating the "checkOverdueCases.php" file, then execute from the command line. In Linux/UNIX:
In Windows, you will have to change to the directory where php.exe is located. For example:
Code: Select allcd C:\Users\Bob\AppData\Roaming\ProcessMaker-3_0_1_7\php
php -f checkOverdueCases.php
After verifying that the script runs without any problems, then set the script to execute periodically as a Scheduled Task in Windows or a Cron job in Linux/UNIX. See:
http://wiki.processmaker.com/3.0/Executing_cron.php
I haven't tested this code, so let me know if this example works, so I can add it to the wiki for others to use.