Questions and discussion about using ProcessMaker: user interface, running cases & functionality
By heemalkumar
#816144
Hi All
I have a process where a User selects which department they belong to.
For a particular type of department selection, i want an email to go to few key stakeholders with the attachments when case is submitted.

How do I go about doing this.
User avatar
By amosbatto
#816151
You can use departments to do this, but departments in ProcessMaker are very inflexible, so I recommend creating groups for each department and letting the user select the group in a dropdown box.

Let's say that you have a dropdown box with a list of the group names which represent departments and this dropdown is associated with the variable "sendToGroup". Let's also say that you have used the Public Files manager to upload the files "quarterlyReport.doc" and "managersReport.doc" and "salesReport.doc".

Then, the following trigger code executed after the Dynaform that contains the dropdown will send the email to the members of the group and select the file based on the group name.
Code: Select all
if (!empty(@@sendToGroup)) {
   $groupId = PMFGetGroupUID(@@sendToGroup);
   if (empty($groupId)) {
      throw new Exception("Group '".@@sendToGroup."' doesn't exist.");
   }
   $aUsers = PMFGetGroupUsers($groupId);
   $to = '';

   foreach ($aUsers as $aUser) {
      $to .= (empty(to) ? '' : ', ') . $aUser['USR_EMAIL'];
   }
   
   //select attachment to send based on the name of the group:
   if (@@sendToGroup == 'Sales') {
       $aAttach = array( PATH_DATA_PUBLIC . @@PROCESS . PATH_SEP . 'salesReport.doc' );
   }
   elseif (@@sendToGroup == 'Managers') {
       $aAttach = array( PATH_DATA_PUBLIC . @@PROCESS . PATH_SEP . 'managersReport.doc' );
   }
   else {
       $aAttach = array( PATH_DATA_PUBLIC . @@PROCESS . PATH_SEP . 'quarterlyReport.doc' );
   }
  
   PMFSendMessage(@@APPLICATION, 'admin@example.com', $to, '', '', 'Check report', 
           'reportTemplate.html', array(), $aAttach); 
}
#816154
You could do it like this:
Code: Select all
$aAttach = array():
foreach ($aUsers as $aUser) {
      if ($aUser['USR_USERNAME'] == 'george')
          $aAttach[] = PATH_DATA_PUBLIC . @@PROCESS . PATH_SEP . 'georgeReport.doc';
      }
     elseif ($aUser['USR_USERNAME'] == 'jane')
          $aAttach[] = PATH_DATA_PUBLIC . @@PROCESS . PATH_SEP . 'janeReport.doc';
      }
              
      $to .= (empty(to) ? '' : ', ') . $aUser['USR_EMAIL'];
}
#816156
Sorry Amos.
Struggling to do this.
If you can help me with the trigger.

Attached is my dynaform. The variable of the attachment is 'wrap'. Its a multipleFile type.

How do i set the trigger, so that whatever is being attached in this dynaform, it is emailed to a user 'admin@processmaker.com' after form is submitted.
Attachments
Add description
(25.75 KiB) Downloaded 243 times
Want to create your own meme coin?

In the world of cryptocurrencies, a unique and exc[…]

The market for cryptocurrencies is demonstrating a[…]

What's SAP FICO?

Embarking on a dissertation can be one of the most[…]

Hello. For rental housing, there are software solu[…]