How to send reminder / mail notification to manager in case task wasn't completed in time?

Questions and discussion about using ProcessMaker: user interface, running cases & functionality

Moderator: amosbatto

nypreh
Posts: 1
Joined: Thu May 19, 2016 5:09 am
Country: Azerbaijan

How to send reminder / mail notification to manager in case task wasn't completed in time?

Unread postby nypreh » Thu May 19, 2016 5:19 am

Hi all,

I saw similar question here, but it wasn't explained clearly:

http://forum.processmaker.com/viewtopic.php?f=41&t=708808

Let's assume that I have process which consist of 2 tasks (Task_1 and Task_2).
I set Timing Control in Task_2 properties, so Task_2 should be completed in 2 days.
Now I would like processmaker to send mail notification to assigned users after 2 days passed and also same mail (or put additional mails to CC) of managers or other persons.

Can you please let me know how I can achieve it, since I couldn't find in documentation?

Thanks in advance.

amosbatto
Posts: 5834
Joined: Mon Jun 22, 2009 10:28 am
Country: Bolivia
Location: La Paz
Contact:

Re: How to send reminder / mail notification to manager in case task wasn't completed in time?

Unread postby amosbatto » Thu May 19, 2016 10:20 pm

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 all

Dear @#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 = '[email protected]';

$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'[email protected]#SYS_SYS.'/'[email protected]#SYS_LANG.'/'[email protected]#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:

Code: Select all

php -f checkOverdueCases.php

In Windows, you will have to change to the directory where php.exe is located. For example:

Code: Select all

cd 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.
Amos B. Batto ♦ ProcessMaker Technical Documentation Writer & Forum Manager ♦ Cofounder of ILLA (http://www.illa-a.org)

azalea
Posts: 9
Joined: Wed Aug 19, 2015 7:46 am
Country: South Africa

Re: How to send reminder / mail notification to manager in case task wasn't completed in time?

Unread postby azalea » Wed Sep 21, 2016 4:04 am

Dear All
I have tried the above solution, the only difference is that I need the trigger to send the message after 1 day. On review of the APP_CACHE_VIEW database I noticed some minor differences that I corrected.

Code: Select all

$taskId = '81312924357dfd963394c69047342114';

$emailFrom = '[email protected]';

$twoDaysAgo = date('Y-m-d H:i:s', strtotime('-1 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_TAS_TITLE'],
      'taskAssignedDate' => $aCase['DEL_DELEGATE_DATE'],
      'taskDueDate' => $aCase['DEL_TASK_DUE_DATE'],
      'caseCreatedBy' => $aCaseInfo['USR_UID'],
      'caseStartDate' => $aCaseInfo['APP_CREATE_DATE'],
      'caseUpdatedDate'=> $aCaseInfo['APP_UPDATE_DATE'],
      'caseLink' => (G::is_https() ? "https://" : "http://") . $_SERVER['SERVER_NAME'] .
          ':' . $_SERVER['SERVER_PORT'] . //comment out if no port number
          '/sys'[email protected]#SYS_SYS.'/'[email protected]#SYS_LANG.'/'[email protected]#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);
}

When I run checkOverdueCases.php command I receive the following response as attached.

checkOverdueCases_Output.jpg
(149.87 KiB) Downloaded 25 times


On running the cron.php script no emails are sent.
cron.jpg
(69.52 KiB) Downloaded 25 times


The cron log on the server shows timereventcron as 'Failed'
cronlog.jpg
(7.33 KiB) Downloaded 25 times


I am not sure if anyone else has tried this. If so can anyone help.

Thanks
Aza

amosbatto
Posts: 5834
Joined: Mon Jun 22, 2009 10:28 am
Country: Bolivia
Location: La Paz
Contact:

Re: How to send reminder / mail notification to manager in case task wasn't completed in time?

Unread postby amosbatto » Wed Sep 21, 2016 2:50 pm

It looks like you are using backticks ( ` ) instead of single quotation marks ( ' ) in your code. At least that is the way that DOS is showing them in your screenshot. That would cause problems in PHP.
Amos B. Batto ♦ ProcessMaker Technical Documentation Writer & Forum Manager ♦ Cofounder of ILLA (http://www.illa-a.org)

medoman
Posts: 32
Joined: Thu Nov 24, 2016 6:49 am
Country: United States of America

Re: How to send reminder / mail notification to manager in case task wasn't completed in time?

Unread postby medoman » Tue Dec 27, 2016 7:45 am

it worked with me.but the syntax of the sendmessage in the trigger is not correct ... i corrected it and its fine ... thank you

azatrath
Posts: 24
Joined: Thu Oct 12, 2017 3:38 am
Country: Turkey

Re: How to send reminder / mail notification to manager in case task wasn't completed in time?

Unread postby azatrath » Thu Jan 04, 2018 4:54 am

amosbatto wrote: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 all

Dear @#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 = '[email protected]';

$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'[email protected]#SYS_SYS.'/'[email protected]#SYS_LANG.'/'[email protected]#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:

Code: Select all

php -f checkOverdueCases.php

In Windows, you will have to change to the directory where php.exe is located. For example:

Code: Select all

cd 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.


hi amos,

i was using this method with bitnami installer. after that i installed manual installer PM 3.2.1. this script gave me an error about wrong paswoord. my password is same as old which is working with bitnami installer. i have also tried http://wiki.processmaker.com/3.0/ProcessMaker_WSDL_Web_Services#Using_Hashed_Passwords_from_the_Database this one same error. i cant find any solution about it. can you help me ?
Attachments
Adsız.png
Adsız.png (114.17 KiB) Viewed 302 times

amosbatto
Posts: 5834
Joined: Mon Jun 22, 2009 10:28 am
Country: Bolivia
Location: La Paz
Contact:

Re: How to send reminder / mail notification to manager in case task wasn't completed in time?

Unread postby amosbatto » Thu Jan 04, 2018 6:36 pm

azatrath,
I assume that you upgraded to a more recent version of MySQL that uses SHA256 in place of MD5 to store passwords.

In your code, change this line from:

Code: Select all

$md5Pass 'md5:' md5($password); 

To:

Code: Select all

$md5Pass 'md5:'hash('sha256',$password); 
Amos B. Batto ♦ ProcessMaker Technical Documentation Writer & Forum Manager ♦ Cofounder of ILLA (http://www.illa-a.org)

fibo2358
Posts: 31
Joined: Wed Nov 16, 2016 6:35 am
Country: Poland

Re: How to send reminder / mail notification to manager in case task wasn't completed in time?

Unread postby fibo2358 » Mon Feb 12, 2018 8:06 am

Hello Amos,

I think that the possibility to send a reminder could be a standard functionality of ProcessMaker in the task definition, such as a time limit to claim a case:
(http://wiki.processmaker.com/3.1/Tasks#Setting_time_limit_to_claim_a_case).
Is it possible to include such a functionality in a future version?
1. On the task level, the option to define a notification when the time is before to the task due-date.
2. On the task level, the option to define a notification when the time is after the task due-date.

Regards,
fibo2358

amosbatto
Posts: 5834
Joined: Mon Jun 22, 2009 10:28 am
Country: Bolivia
Location: La Paz
Contact:

Re: How to send reminder / mail notification to manager in case task wasn't completed in time?

Unread postby amosbatto » Wed Feb 14, 2018 11:26 pm

fibo2358 wrote:I think that the possibility to send a reminder could be a standard functionality of ProcessMaker in the task definition, such as a time limit to claim a case:
(http://wiki.processmaker.com/3.1/Tasks#Setting_time_limit_to_claim_a_case).
Is it possible to include such a functionality in a future version?
1. On the task level, the option to define a notification when the time is before to the task due-date.
2. On the task level, the option to define a notification when the time is after the task due-date.

I agree, but I don't have any control over future development of PM.
If you want the PM developers to see this, please file a bug report about it at: http://bugs.processmaker.com
Amos B. Batto ♦ ProcessMaker Technical Documentation Writer & Forum Manager ♦ Cofounder of ILLA (http://www.illa-a.org)


Return to “Using ProcessMaker 3”

Who is online

Users browsing this forum: Google [Bot] and 6 guests