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 allif (!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);
}