Questions and discussion about using ProcessMaker: user interface, running cases & functionality
#816104
Hi Amo,

I'm using PM 3.2.2, and I tried to generate an output document and then send as attachemnt in an email.

Any ideas on how to combine the following code into one trigger?


Example Emailing Generated Output Document Files:
Code: Select all
//set to the Output Document definition's unique ID:
$outDocDef = "691319281570bc9938b4460028767596";
$caseUID = @@APPLICATION; //Unique ID for the current case
$aAttachFiles = array();

$outDocQuery = "SELECT AD.APP_DOC_UID, AD.DOC_VERSION, C.CON_VALUE AS FILENAME
   FROM APP_DOCUMENT AD, CONTENT C
   WHERE AD.APP_UID='$caseUID' AND AD.DOC_UID='$outDocDef' AND
   AD.APP_DOC_STATUS='ACTIVE' AND AND AD.APP_DOC_UID = C.CON_ID AND
   C.CON_CATEGORY = 'APP_DOC_FILENAME' AND AD.DOC_VERSION = C.CON_PARENT
   ORDER BY AD.DOC_VERSION DESC";

$outDoc = executeQuery($outDocQuery);

if (!empty($outDoc)) {
   $g = new G();
   $path = PATH_DOCUMENT . $g->getPathFromUID($caseUID) . PATH_SEP . 'outdocs'. PATH_SEP .
      $outDoc[1]['APP_DOC_UID'] . '_' . $outDoc[1]['DOC_VERSION'];
   $filename = $outDoc[1]['FILENAME'];
   $aAttachFiles[$filename . '.pdf'] = $path . '.pdf';  //remove if not generating a PDF file
   $aAttachFiles[$filename . '.doc'] = $path . '.doc'; //remove if not generating a DOC file
}

$usr = userInfo(@@USER_LOGGED);
$from = "admin@processmaker.com"; //set to the email account set in Admin > Email Servers
@@resp=PMFSendMessage(@@APPLICATION, $from, $usr['mail'], "", "",
   "Case Report", "caseReportTemplate.html", array(), $aAttachFiles);
Generate output document
Code: Select all
//set to the Unique ID of the Output Document:
$outDocId = '84581368556d0b69010a355067195050';
$caseId = @@APPLICATION;

PMFGenerateOutputDocument($outDocId);

//retrieve info from the database about the generated output document file
$query = "SELECT APP_DOC_UID FROM APP_DOCUMENT WHERE APP_UID='$caseId' AND
   DOC_UID='$outDocId' AND APP_DOC_STATUS='ACTIVE'";
$result = executeQuery($query);

if (!is_array($result) or count($result) == 0) {
   die("Error: Unable to find generated Output Document in database.");
}

$d = new AppDocument();
$aFile = $d->Load( $result[1]['APP_DOC_UID'] );

//change from 'http://' to 'https://' if using SSL
//change 'pdf' to 'doc' for MS Word file
@@outDocUrl = 'http://' . $_SERVER['SERVER_NAME'] .
   // ':' . $_SERVER['SERVER_PORT'] . //uncomment if needing a port number
   '/sys'. @@SYS_SYS . '/en/neoclassic/cases/cases_ShowOutputDocument?a=' .
   $aFile['APP_DOC_UID'] . '&v='. $aFile['DOC_VERSION'] . '&ext=pdf';
@@outDocFilename = $aFile['APP_DOC_FILENAME'] .'_'. $aFile['DOC_VERSION'] .'.pdf';
Many Thanks,
Yuan
#816105
Yuan, I don't see any errors in your code. You need to add case variables and check their values in the debugger, like this:
@@outDoc = $outDoc;
@@outDocQuery = $outDocQuery;

Do that for every major variable until you discover the problem.
#816146
Hi Amo,

I found the issue since there is an error on the wiki website,
https://wiki.processmaker.com/3.2/Proce ... sage.28.29
Example Emailing Generated Output Document Files:
Code: Select all
//set to the Output Document definition's unique ID:
$outDocDef = "691319281570bc9938b4460028767596";
$caseUID = @@APPLICATION; //Unique ID for the current case
$aAttachFiles = array();

$outDocQuery = "SELECT AD.APP_DOC_UID, AD.DOC_VERSION, C.CON_VALUE AS FILENAME
   FROM APP_DOCUMENT AD, CONTENT C
   WHERE AD.APP_UID='$caseUID' AND AD.DOC_UID='$outDocDef' AND
   AD.APP_DOC_STATUS='ACTIVE' AND AND AD.APP_DOC_UID = C.CON_ID AND
   C.CON_CATEGORY = 'APP_DOC_FILENAME' AND AD.DOC_VERSION = C.CON_PARENT
   ORDER BY AD.DOC_VERSION DESC";

$outDoc = executeQuery($outDocQuery);

if (!empty($outDoc)) {
   $g = new G();
   $path = PATH_DOCUMENT . $g->getPathFromUID($caseUID) . PATH_SEP . 'outdocs'. PATH_SEP .
      $outDoc[1]['APP_DOC_UID'] . '_' . $outDoc[1]['DOC_VERSION'];
   $filename = $outDoc[1]['FILENAME'];
   $aAttachFiles[$filename . '.pdf'] = $path . '.pdf';  //remove if not generating a PDF file
   $aAttachFiles[$filename . '.doc'] = $path . '.doc'; //remove if not generating a DOC file
}

$usr = userInfo(@@USER_LOGGED);
$from = "admin@processmaker.com"; //set to the email account set in Admin > Email Servers
@@resp=PMFSendMessage(@@APPLICATION, $from, $usr['mail'], "", "",
   "Case Report", "caseReportTemplate.html", array(), $aAttachFiles);
In the query $outDocQuery, there is a duplicate "AND" between "APP_DOC_STATUS" and "APP_DOC_UID".

Hopefully, this can be updated.

Thanks,
Yuan
#816149
Thanks Yuan for spotting that. I think I introduced that error a couple weeks ago when somebody on the forum pointed out a way to shorten the SQL query in that code example and I didn't retest the code with the new query. I have fixed it on the wiki.

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

Experience heightened pleasure with Cenforce 100 M[…]

Get an instant solution to move emails to MBOX for[…]

Most Demanding OST to PST Converter

The most demanding OST to PST Converter is TrijaT[…]