Send reason for pausing case in an email to participating users in case

From pmusers
Jump to: navigation, search

This programming example shows how to include the reason for pausing a case in an email which is sent to all the users who have participated in the case.

Process: Send_case_note_in_email_when_pausing-1.pmx (right click and select Save link as)
Author: Amos Batto (
Version: 1.0 (2018-06-11)
Tested in: ProcessMaker 3.2.0 Community in Debian 8.4 with PHP 5.6.20

First, create an email template named "pausedNote.html" which contains the variable @#body. This variable will hold the contents of a Case Note which is created when a user enters the reason for pausing a case.


Then, create the following trigger in the process, which will lookup the reason why the case has been paused and send out that reason in an email:

$caseId = @@APPLICATION;
$userId = @@USER_LOGGED;
$last20Seconds = date("Y-m-d H:i:s", strtotime("-20 seconds"));

   WHERE APP_UID='$caseId' AND USR_UID='$userId' AND NOTE_DATE >= '$last2Seconds'
$aNotes = executeQuery($sql);

//if only want to email a case note if included in the reason why the case
//was paused 
if (count($aNotes)) {
   $aInfo = userInfo($userId);
   $userFullName = $aInfo['firstname'].' '.$aInfo['lastname'].' ('.$aInfo['username'].')';
   $body = "<i>Note posted by $userFullName on {$aNotes[1]['NOTE_DATE']}:</i><br>\n".
   $oCases = new Cases();
   $aUsers = $oCases->getUsersParticipatedInCase(@@APPLICATION)['array'];
   $to = '';
   foreach ($aUsers as $aUser) {
      $to .= (empty($to) ? '' : ', ') . $aUser['USR_EMAIL'];
   //set to email of account configured in Admin > Email Servers:
   $from = ''; 
   $subject = "Case #".@@APP_NUMBER." paused by ".@@USR_USERNAME;
   $aVars = array( 'body' => $body );
   PMFSendMessage(@@APPLICATION, $from, $to, '', '', $subject, 'pausedNote.html', $aVars);

This trigger first queries the APP_NOTES table in the database for a case note created in the last 20 seconds by the logged-in user in the current case. If it finds a case note matching that criteria, then it places the reason that the user entered for pausing the case in the variable $body and passes that in an array of variables to be inserted in the email template. In addition, it uses the Cases::getUsersParticipatedInCase() function to construct the list of users who will receive the email. Then, it uses PMFSendMessage() to send out the email to those users.

Finally, right click on a blank area in the process map, and select Edit Process from the context menu. In the properties of the process, select the name of the trigger which was just defined in the Execute a trigger when a case is paused dropdown:


Now, when a case is paused:


An email with the reason for pausing the case will be sent out to the users who participated in the case: