Questions and discussion about using ProcessMaker: user interface, running cases & functionality
By cmeier
#788605
Hi

I need to use the PMFSendMessage() function to send an email with an attachment. The problem is that the file I'm trying to send is not a file that was uploaded in the case. Instead, it's a template file I uploaded into a folder I created in the processmaker file system. I found this example in the wiki, but I don't understand how the path is constructed and how to modify it for my folder:
Code: Select all
$aAttachFiles = array(
    PATH_DATA_PUBLIC . @@PROCESS . PATH_SEP . 'companyLogo.png',
    PATH_DATA_PUBLIC . @@PROCESS . PATH_SEP . 'companyProfile.pdf'
);
$usr = userInfo(@@USER_LOGGED);
PMFSendMessage(@@APPLICATION, 'manager@acme.com', $usr['mail'], '', '', 
   'Company Information', 'companyInfoTemplate.html', array(), $aAttachFiles);
My folder is /TEMPLATES

Thanks.

Chris
#788608
Chris, since I'm not sure exactly where you placed the folder on the ProcessMaker server, I can't tell you how to construct the path from inside PM.
However, if your full path on the server is "/opt/processmaker/TEMPLATES", then do it this way:
Code: Select all
$aAttachFiles = array(
    '/opt/processmaker/TEMPLATES/companyLogo.png',
    '/opt/processmaker/TEMPLATES/companyProfile.pdf'
);
$usr = userInfo(@@USER_LOGGED);
PMFSendMessage(@@APPLICATION, 'manager@acme.com', $usr['mail'], '', '',
   'Company Information', 'companyInfoTemplate.html', array(), $aAttachFiles);
By cmeier
#788619
Hi, thanks for the reply

I placed the folder in the processmaker filesystem. I was asking because as far as I know, ProcessMaker manages that using some form of ID naming for folders, not the names that are displayed by the ProcessMaker file sistem.

I'll try your solution.

Cheers,

Chris
#788621
Oh you mean the "Templates" directory in the graphical interface. Those files are saved in:
{install-directory}/shared/sites/workflow/mailTemplates/{process-UID}/{filename}
For example:
/opt/processmaker/shared/sites/workflow/mailTemplates/58038459456cf8d46c99432086930679/notifyUser.html

From a trigger you can access this file with:
PATH_DATA_MAILTEMPLATES .@@PROCESS .PATH_SEP."notifyUser.html"
By cmeier
#788622
amosbatto wrote:Oh you mean the "Templates" directory in the graphical interface. Those files are saved in:
{install-directory}/shared/sites/workflow/mailTemplates/{process-UID}/{filename}
For example:
/opt/processmaker/shared/sites/workflow/mailTemplates/58038459456cf8d46c99432086930679/notifyUser.html

From a trigger you can access this file with:
PATH_DATA_MAILTEMPLATES .@@PROCESS .PATH_SEP."notifyUser.html"
No... I think the name "Templates" was a very unfortunate name pick. Sorry for the confusion...

I went into the ProcessMaker file system and manually created a directory called templates. I'm attaching a picture so its clearer.
Inside that folder, I manually uploaded two files, and I want to be able to fetch the with a trigger and send them by email. Since the files were uploaded manually, they dont have a process UID! :P
Attachments
Capture.PNG
Capture.PNG (54.32 KiB) Viewed 8205 times
#788624
Download the file from the ProcessMaker interface in Home > Documents. Then, in your web browser, go to the Download Manager and copy the URL to the file.
It should be something like
Code: Select all
http://pm.localhost/sysworkflow/en/neoclassic/cases/cases_ShowDocument?a=965821362588279cb660237001025225&v=1
If you didn't upload this file inside a case, then it will be stored on your server with a path like:
/opt/processmaker/shared/sites/workflow/files/00000000000000000000000000000000/965/821/362/588279cb660237001025225_1.png

To access this file from inside a trigger use this code:
Code: Select all
$appDocId = '965821362588279cb660237001025225';
$docVersion = 1;
//get file extension from the filename:
$d = new AppDocument();
$aFile = $d->Load($appDocId, $docVersion);
$ext = pathinfo($aFile['APP_DOC_FILENAME'], PATHINFO_EXTENSION);
$filePath = PATH_DOCUMENT . '00000000000000000000000000000000' . PATH_SEP . 
   G::getPathFromUID($appDocId) .'_'. $docVersion .'.'. $ext;
#828717
amosbatto wrote: Thu Jan 19, 2017 7:22 pm Chris, since I'm not sure exactly where you placed the folder on the ProcessMaker server, I can't tell you how to construct the path from inside PM.
However, if your full path on the server is "/opt/processmaker/TEMPLATES", then do it this way:
Code: Select all
$aAttachFiles = array(
    '/opt/processmaker/TEMPLATES/companyLogo.png',
    '/opt/processmaker/TEMPLATES/companyProfile.pdf'
);
$usr = userInfo(@@USER_LOGGED);
PMFSendMessage(@@APPLICATION, 'manager@acme.com', $usr['mail'], '', '',
   'Company Information', 'companyInfoTemplate.html', array(), $aAttachFiles);
Hello amos,
I follow your code and i can't send my attachment to email, here's my code
Code: Select all
if (isset(@@suratizin_label) and @@suratizin_label != '[]') { 
   $filename = json_decode(@@suratizin_label)[0];
   if (!empty(@@suratizin)) {
	   $fileId = json_decode(@@suratizin)[0];
	}
	else {
	   $sql = "SELECT * FROM APP_DOCUMENT WHERE APP_UID='".@@APPLICATION."' AND APP_DOC_STATUS='ACTIVE' 
		  AND APP_DOC_FIELDNAME='suratizin'";
	   $result = executeQuery($sql);
	   if (empty($result)) {
		   throw new Exception("No uploaded file for this case.");
	   }
	   $fileId = $result[1]['APP_DOC_UID']; 
	}
   $ext = pathinfo($filename, PATHINFO_EXTENSION);
	
   $d = new AppDocument();
   $aFile = $d->Load($fileId);
   $g = new G();
   $path_suratizin = PATH_DOCUMENT . $g->getPathFromUID(@@APPLICATION) . PATH_SEP .
	   $fileId .'_'. $aFile['DOC_VERSION'] .'.'. $ext;
   
   @@path_suratizin = $path_suratizin;
	
	$aAttachFiles = array(
		@@path_suratizin
	);
}

$query = "UPDATE gundala SET surat_izin = '".$surat_izin."',status_surat_izin = '".$status_surat_izin."' WHERE id = '".$last_id."'";

executeQuery($query,$db);

$case_id = @@APPLICATION;
$from = '';
$to = @@email_mhs;
$cc = '';
$bcc= '';
$subject = '[GUNDALA] Informasi Kegiatan';
$template = 'InformasiKegiatan1.html';
PMFSendMessage($case_id,$from,$to,$cc,$bcc,$subject,$template,array(), $aAttachFiles);
//PMFSendMessage($case_id,$from,$to,$cc,$bcc,$subject,$template);

A 1xbet clone script is a pre-designed software so[…]

4rabet clone script is enabling entrepreneurs to e[…]

Parimatch clone script is enabling entrepreneurs t[…]

In the world of cryptocurrency, a wallet is an app[…]