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

Moderator: amosbatto

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.
#790715
Sorry for the lengthy title. (haha :D )
We have a timer based process to create a case and convert each new fax we receive so we can upload the converted file and attach the file to the new case so our employees can see this document and define what type of document it is in our business process.

We successfully scan the directory for all files and convert them from tiff format to pdf.
The Case is created no problem.
Our Issue is we can not upload the file to the input document of the new case we created.

So, here is some things i can outline to help find a solution to our issue.
We have setup a local instance of ProcessMaker with ubuntu 14.04 on our server.
On this server we have a network based storage system. It's setup to catch and maintain our inbound faxes. The processmaker instance has appropriate access to read and write to our server storage.

Here is the code we came up with for our task:
( we started using manual id's for testing )
Code: Select all
@@processID = '58449516358ed01bd715b81061373477';
@@taskID = '67431826958ed01e82eaf13001019125';
@@userID = '68748242358e418af747e20000456094';
$directory = "/media/network/faxfolder/";
$directory_listing = scandir($directory);
$filenames = array();
foreach ($directory_listing as $directory_item) {
	$file_name_and_path = '';
	$file_name_and_path .= $directory;
	$file_name_and_path .= $directory_item;
	$filenameonly = reset(explode(".", $directory_item));
	if(is_file($file_name_and_path)){
		$filesize = filesize($file_name_and_path);
		$newCaseID = PMFNewCase(@@processID, @@userID, @@taskID, array());
		$convert_command = "tiff2pdf ";
		$convert_command .= $directory;
		$convert_command .= $directory_item;
		$convert_command .= " -o ";
		$convert_command .= "/media/network/faxfolder/converted_to_pdf/";
		$convert_command .= $filenameonly;
		$convert_command .= ".pdf";
		$convert_the_file = exec($convert_command);
		//$remove_command = "rm ";
		//$remove_command .= $directory;
		//$remove_command .= $directory_item;
		//$delete_the_original_tiff_file = exec($remove_command);
		if ($newCaseID) {
			$c = new Cases();
			$aCase = $c->loadCase($newCaseID);
			$aCase['APP_STATUS'] = 'TO_DO';
			$c->updateCase($newCaseID, $aCase);
			$path = '$directory';
			$path .= 'converted_to_pdf/';
			$path .= $filenameonly;
			$path .= '.pdf';
			$newDocumentID = PMFAddInputDocument('56731602658ee510d97e972098145137', null, 1, 'INPUT', 'test input file', null, '$newCaseID', '1', '67431826958ed01e82eaf13001019125', '68748242358e418af747e20000456094', 'file', '/media/network/faxfolder/converted_to_pdf/TestFile.pdf'
			);
			if($newDocumentID){//testing if AddInputDoc funciton ran
				$reportederror = executeQuery("INSERT INTO PMT_ERRORS (ERROR_DATA) VALUES ('$newDocumentID')");
			}else{
				$reportederror = executeQuery("INSERT INTO PMT_ERRORS (ERROR_DATA) VALUES ('Document Not Created.')");
			}
			$result = executeQuery("INSERT INTO PMT_FAXES (FAX_CASEID, FAX_FILENAME, FAX_FILESIZE) VALUES ('$newCaseID', CURDATE(), CURTIME())");
		};
	};
};
I'm not the most experienced with php so i'm sorry if you're cringing at my code.
any help is greatly appreciated. :D
#790722
In PHP, you can't insert variables inside single quoted strings. Variables can only be inserted inside double quoted strings. However, you only need to use quotation marks around literal strings, not around variables holding strings. In the PMFAddInputDocument() function call, change '$newCaseID', '1' to $newCaseID, 1

Try this:
Code: Select all
@@processID = '58449516358ed01bd715b81061373477';
@@taskID = '67431826958ed01e82eaf13001019125';
@@userID = '68748242358e418af747e20000456094';
$directory = "/media/network/faxfolder/";
$directory_listing = scandir($directory);
$filenames = array();
foreach ($directory_listing as $directory_item) {
   $file_name_and_path = $directory . $directory_item;
   $filenameonly = reset(explode(".", $directory_item));
   if(is_file($file_name_and_path)){
      $filesize = filesize($file_name_and_path);
      $newCaseID = PMFNewCase(@@processID, @@userID, @@taskID, array());
      $convert_command = "tiff2pdf {$directory}{$directory_item}  -o ".
          "/media/network/faxfolder/converted_to_pdf/{$filenameonly}.pdf";
      $convert_the_file = exec($convert_command);
      //$remove_command = 'rm '.$directory . $directory_item;
      //$delete_the_original_tiff_file = exec($remove_command);
      if ($newCaseID) {
         $c = new Cases();
         $aCase = $c->loadCase($newCaseID);
         $aCase['APP_STATUS'] = 'TO_DO';
         $c->updateCase($newCaseID, $aCase);
         $path = $directory . 'converted_to_pdf/' . $filenameonly . '.pdf';
         $newDocumentID = PMFAddInputDocument('56731602658ee510d97e972098145137', null, 1, 'INPUT', 
            'test input file', null, $newCaseID, 1, '67431826958ed01e82eaf13001019125',
            '68748242358e418af747e20000456094', 'file', $path);
         if ($newDocumentID) { //testing if AddInputDoc funciton ran
            $reportederror = executeQuery("INSERT INTO PMT_ERRORS (ERROR_DATA) VALUES ('$newDocumentID')");
         } else {
            $reportederror = executeQuery("INSERT INTO PMT_ERRORS (ERROR_DATA) VALUES ('Document Not Created.')");
         }
         $result = executeQuery("INSERT INTO PMT_FAXES (FAX_CASEID, FAX_FILENAME, FAX_FILESIZE) VALUES ('$newCaseID', CURDATE(), CURTIME())");
      };
   };
};

As you have got seen that after every single updat[…]

issue with processmaker 3.2

Hello! The solution to your question is the foll[…]

BPMN project disappeared

Hi Alex! , maybe you forgot to save your process[…]

mcrypt extension is deprecated!

Hello Ehsan! If you did not find the mcrypt ext[…]