Page 1 of 1

How to send an output file (pdf) via email?

Posted: Mon Feb 11, 2019 12:11 pm
by ericopro
Hi everyone,

I was working with Processmaker and I made a PDF as an output summary file, and now, I would like to send this PDF to the creator of the process via email, but I don't know how to do it...
Can you give me any clue about that?


Thank you in advance!

Re: How to send an output file (pdf) via email?

Posted: Mon Feb 11, 2019 4:03 pm
by ziadeh
You can use this code in a trigger:
Code: Select all

$outDocId = '2862978795bc32764032f25090467465'; // <--- Your output Document ID  
$caseId = @@APPLICATION;   
$aAttachFiles = array(); 
$g = new G(); 

$docQuery = "SELECT AD.APP_DOC_UID, AD.DOC_VERSION, C.CON_VALUE AS FILENAME FROM APP_DOCUMENT AD, CONTENT C WHERE AD.APP_UID='$caseId' AND AD.APP_DOC_STATUS='ACTIVE' AND
   AD.APP_DOC_UID = C.CON_ID AND C.CON_CATEGORY = 'APP_DOC_FILENAME' AND AD.DOC_UID='$outDocId'";
$docs = executeQuery($docQuery);
  
if (is_array($docs)) {
    foreach ($docs as $doc) {
        $aAttachFiles[$doc['FILENAME'] . '.pdf'] = PATH_DOCUMENT . $g->getPathFromUID(@@APPLICATION) . PATH_SEP . "outdocs" . PATH_SEP . $doc['APP_DOC_UID'] . "_" . $doc['DOC_VERSION'] . ".pdf";
   }
}

$to = '[email protected]';
$subject = "Test Email";  

PMFSendMessage(@@APPLICATION, $from, $to, ' ', ' ', $subject, 'emailTemplate.html',  '', $aAttachFiles);

Also you can use this code to include the uploaded documents with the generated document:
Code: Select all

$outDocId = '2862978795bc32764032f25090467465';  // <--- Your output Document ID
$caseId = @@APPLICATION;   
$aAttachFiles = array(); 
$g = new G(); 

$docQuery = "SELECT AD.DOC_UID, AD.APP_DOC_UID, AD.DOC_VERSION, C.CON_VALUE AS FILENAME FROM APP_DOCUMENT AD, CONTENT C WHERE AD.APP_UID='$caseId' AND AD.APP_DOC_STATUS='ACTIVE' AND
   AD.APP_DOC_UID = C.CON_ID AND C.CON_CATEGORY = 'APP_DOC_FILENAME'";
$docs = executeQuery($docQuery);
  
if (is_array($docs)) {
    foreach ($docs as $doc) {
		if($doc["DOC_UID"] == $outDocId) {
        $aAttachFiles[$doc['FILENAME'] . '.pdf'] = PATH_DOCUMENT . $g->getPathFromUID(@@APPLICATION) . PATH_SEP . "outdocs" . PATH_SEP . $doc['APP_DOC_UID'] . "_" . $doc['DOC_VERSION'] . ".pdf";
		} else {
		
        $aAttachFiles[$doc['FILENAME']] = PATH_DOCUMENT . $g->getPathFromUID(@@APPLICATION) . PATH_SEP . "outdocs" . PATH_SEP . $doc['APP_DOC_UID'] . "_" . $doc['DOC_VERSION'];	
		}
   }
}
 

$to = '[email protected]';
$subject = "Test Email";  
PMFSendMessage(@@APPLICATION, $from, $to, ' ', ' ', $subject, 'emailTemplate.html',  '', $aAttachFiles);

Re: How to send an output file (pdf) via email?

Posted: Tue Feb 12, 2019 1:04 pm
by ericopro
Thanks for your answer!
But when I write this code and I execute the process, I get this error:

Non-static method G::sqlEscape() should not be called statically (line 1712):


So unfortunately, is not working for me :(

Re: How to send an output file (pdf) via email?

Posted: Tue Feb 12, 2019 5:21 pm
by ziadeh
That code worked with me. What version of PM are you using? What version of PHP? What operating system?

if you are using linux, try to edit PHP {your php version} configuration file php.ini:
Code: Select all
sudo nano /etc/php/{your php version}/apache2/php.ini 
Search for the following line and edit it using the following configuration:
Code: Select all
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
Then restart apache
Code: Select all
systemctl restart apache2.service

Re: How to send an output file (pdf) via email?

Posted: Wed Feb 13, 2019 6:53 am
by ericopro
I had an error on my output document, I fixed it and now it works properly!

Thank you! :D