Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.

Moderators: ArturoRobles, ArturoRobles

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.
By azalea45
#790650
Hi All,

We have a process that produces one of 5 output documents and as the last stage of the process, emails the document to the process initiator. The document has a specific format as per certain government regulations. The government department in question has just informed us that the document does not meet the regulations and we need to re-print all the documents generated for the past month.
The cases in question are all closed.
Is there a way to regenerate the documents in the amended format and re-email them to the task users over the specific date period?
Regards,
Aza
#790656
I created a process that you can use to regenerate an Output Document for any case and select user(s) who participated in the case to receive the generated Output Document file as an attachment in an email.
(33.27 KiB) Downloaded 145 times
Here is the relevant trigger code:
Code: Select all
if (isset(@@action) and @@action == 'GENERATE') {
   $g = new G();
   $caseId = @@selectCase;
   $outDocId = @@selectOutputDoc;
   $sql = "SELECT AD.USR_UID, AD.DEL_INDEX FROM STEP S, APP_DELEGATION AD 
      WHERE S.STEP_UID_OBJ='$outDocId' AND S.TAS_UID=AD.TAS_UID";
   $result = executeQuery($sql);

   $userId = $result[1]['USR_UID'];
   $index  = $result[1]['DEL_INDEX'];	

   PMFGenerateOutputDocument(@@selectOutputDoc, @@selectCase, $index, $userId);
   
   $sql = "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.DOC_UID='$outDocId' AND 
	  AD.APP_DOC_STATUS='ACTIVE' AND AD.APP_DOC_UID = C.CON_ID AND 
	  C.CON_CATEGORY = 'APP_DOC_FILENAME' ORDER BY APP_DOC_CREATE_DATE DESC";
   $aDocSearch = executeQuery($sql);

   if (!is_array($aDocSearch) or count($aDocSearch) == 0) {
      $msg = "Unable to generate Output Document.";	
      $msgType = "ERROR";   
      goto showMsg;
   }
   
   $path = PATH_DOCUMENT . $g->getPathFromUID($caseId) . PATH_SEP . 'outdocs'. PATH_SEP .
      $aDocSearch[1]['APP_DOC_UID'] . '_' . $aDocSearch[1]['DOC_VERSION'];
   $filename = $aDocSearch[1]['FILENAME'];
   $aAttachFiles = array(	
      $filename . '.pdf' => $path . '.pdf',
      $filename . '.doc' => $path . '.doc'
   );
   preg_match('/^\d+/', @@selectCase_label, $aMatch);	
   $msg = "Output document '$filename' was generated for case #".$aMatch[0]; 
   $msgType = 'INFO';
   
   if (count(@=selectUsers) > 0) {
      $to = '';
      foreach (@=selectUsers as $toUserId) {
         $aUser = userInfo($toUserId);
         $to .= (empty($to) ? '' : ', ') . $aUser['mail'];
      }
   
      $aVars = array('selectCase_label' => @@selectCase_label);
       
      @@mailRet = PMFSendMessage(@@APPLICATION, "[email protected]", $to, "", "",
        'Output Document from case #'.$aMatch[0], "sendOutputDoc.html", $aVars, $aAttachFiles);

	  if (@@mailRet) {
		 $msg .= ' and sent as an attachment to '.$to.'.';
	  } else {
		 $msg .= ', but there was a problem sending in email to '.$to.'.';
		 $msgType = "ERROR";   
          }
   }
   showMsg:
   $g->SendMessageText($msg, $msgType);

   //reset form & redirect back to form to select a new case:	
   @@selectProcess = '';
   @@selectCase = '';
   @@selectOutputDoc = '';
   @=selectUsers = array();
   PMFRedirectToStep(@@APPLICATION, @%INDEX, 'DYNAFORM', '442128812590d1f59ae15d1059612309'); 
}
#790701
Hi Amos,

We had a bit of an odd ting happen this morning when trying to re-generate a document.
The document did not pick up any of the variable & when reviewing the case details after the process all the data was gone. Any idea what could have caused this?
#790780
Did you have two cases open at the same time in your web browser? That can cause problems saving data to a case.

If your database is located on a different server than PM, then a firewall or a broken internet connection could also prevent the data from being saved.

If the problem is that session variables are getting reset, then replace this line in your trigger code:
Code: Select all
PMFGenerateOutputDocument(@@selectOutputDoc, @@selectCase, $index, $userId);
With this:
Code: Select all
$g->sessionVarSave();
PMFGenerateOutputDocument(@@selectOutputDoc, @@selectCase, $index, $userId);
$g->sessionVarRestore();

ACTE is a national association representing thousa[…]

ACTE is a national association representing thousa[…]

MSSQLConnection.php on line 367

ACTE is a national association representing thousa[…]

Please, something similar is happening to me. I h[…]