Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
User avatar
By ericopro
#822861
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!
#822862
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 = 'test@domain.com';
$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 = 'test@domain.com';
$subject = "Test Email";  
PMFSendMessage(@@APPLICATION, $from, $to, ' ', ' ', $subject, 'emailTemplate.html',  '', $aAttachFiles);
#822892
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 :(
#822893
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
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[…]