You can associate a File filed with an Input Document, but a MultipleFile field cannot be associated with an Input Document in the properties of the field. The only way to do the associate is to use a trigger which is fired after the DynaForm where the Input Document was uploaded.
There is a PM Function to associate files uploaded in a grid to an Input Document, but I have adapted it to function with a MultipleFile field which is not in a grid. In order to make it work, edit your file workflow/engine/classes/class.pmFunctions.php with a plain text editor. Starting on line 3553, replace the existing definition of the PMFAssociateUploadedFilesWithInputFile() function with the following code:
Code: Select all/**
*
* @method
*
* This function Associates the uploaded files inside a grid with an Input File of the process
*
* @name PMFAssociateUploadedFilesWithInputFile
* @label PMF Associates the uploaded files inside a grid with an Input File of the process
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFAssociateUploadedFilesWithInputFile.28.29
*
* @param string(32) | $inputDocumentUid | Unique id of Input Document | The unique Id of the Input Document which will be associated with the uploaded files
* @param string(32) | $gridVariableName | Name of the grid variable or a MultipleFile variable | Name of the grid variable, that contains the uploaded files or a MultipleFile variable
* @param string(32) | $fileVariableName | ID of File field in grid | ID of the file field in a grid or an empty string if not in a grid
* @param string(32) | $caseUid | Unique id of the case | The unique ID of the case where the files were uploaded
* @param string(32) | $userUid | Unique id of the user | The unique ID of the user who uploaded the files
* @param int | $currentDelIndex | Current index of the case | Current index of the case
*
* @return int | $numberFiles | Number of associated files | Number of files associated with the Input Document
*/
function PMFAssociateUploadedFilesWithInputFile($inputDocumentUid, $variable, $fileVariableName, $caseUid, $userUid, $currentDelIndex)
{
try {
require_once 'classes/model/AppDocument.php';
$appDocument = new AppDocument();
//if $variable is a MultipleFile variable, meaning it is an array of arrays
if (is_array($variable)) {
$aFiles = $variable;
//if no files in the MultipleFile control:
if (count($aFiles) == 0) {
return 0;
}
elseif (!isset($aFiles[0]['appDocUid'])) {
throw new Exception("Bad MultipleFile variable passed to PMFAssociatedUploadedFilesWithInputFile()");
}
foreach ($aFiles as $aFile) {
//Info
$inputDocument = new InputDocument();
$oInpDocData = $inputDocument->load($inputDocumentUid);
//Get the Custom Folder ID (create if necessary)
$appFolder = new AppFolder();
$folderId = $appFolder->createFromPath($oInpDocData['INP_DOC_DESTINATION_PATH'], $caseUid);
$tags = $appFolder->parseTags($oInpDocData["INP_DOC_TAGS"], $caseUid);
//Load the file by its unique identifier, its name, its extension and the path where it's stored
$aDocProps = $appDocument->load($aFile['appDocUid'], $aFile['version']);
$aDocProps['APP_DOC_TYPE'] = 'INPUT';
$aDocProps['DOC_UID'] = $inputDocumentUid;
$aDocProps['FOLDER_UID'] = $folderId;
$aDocProps['APP_DOC_TAGS'] = $tags;
$appDocument->update($aDocProps);
}
return count($aFiles);
}
else { //if the name of a grid variable
$gridVariableName = $variable;
//First step: get all the documents from this case and this grid that are not associated
$criteria = new Criteria('workflow');
$criteria->add(AppDocumentPeer::APP_UID, $caseUid, Criteria::EQUAL);
$criteria->add(AppDocumentPeer::APP_DOC_TYPE, 'ATTACHED', Criteria::EQUAL);
$criteria->add(AppDocumentPeer::APP_DOC_FIELDNAME, $gridVariableName . '_%_' . $fileVariableName, Criteria::LIKE);
$criteria->add(AppDocumentPeer::APP_DOC_STATUS, 'ACTIVE', Criteria::EQUAL);
$criteria->add(AppDocumentPeer::DOC_UID, '-1', Criteria::EQUAL);
$criteria->addAscendingOrderByColumn(AppDocumentPeer::APP_DOC_INDEX);
$numRecTotal = AppDocumentPeer::doCount($criteria);
//If we have an error in the result set, do not continue
if ($numRecTotal == 0) {
//Return
return false;
}
//Query
$rsCriteria = AppDocumentPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$fileCount = 0;
//Search file in the process, associate with the Input document
while ($rsCriteria->next()) {
$row = $rsCriteria->getRow();
//Load the file by its unique identifier, its name, its extension and the path where it's stored
$file = $appDocument->load($row['APP_DOC_UID']);
$ext = pathinfo($file['APP_DOC_FILENAME'], PATHINFO_EXTENSION);
$fileName = $file['APP_DOC_UID'] . '_' . $file['DOC_VERSION'] . '.' . $ext;
$pathFile = PATH_DOCUMENT . G::getPathFromUID($caseUid) . PATH_SEP . $fileName;
$comment = '';
//Delete this file so it can't be uploaded again (Includes Mark Database Record)
$appDocument->remove($file['APP_DOC_UID'], $file['DOC_VERSION']);
$fields = array (
'APP_UID' => $caseUid,
'DEL_INDEX' => $currentDelIndex,
'USR_UID' => $userUid,
'DOC_UID' => $inputDocumentUid,
'APP_DOC_TYPE' => 'INPUT',
'APP_DOC_CREATE_DATE' => date('Y-m-d H:i:s'),
'APP_DOC_COMMENT' => $comment,
'APP_DOC_TITLE' => $file['APP_DOC_TITLE'],
'APP_DOC_FILENAME' => $file['APP_DOC_FILENAME'],
'APP_DOC_FIELDNAME' => ''
);
$result = $appDocument->create($fields);
//Copy the file
$appUid = $appDocument->getAppUid();
$appDocUid = $appDocument->getAppDocUid();
$docVersion = $appDocument->getDocVersion();
$info = pathinfo( $appDocument->getAppDocFilename() );
$extAux = (isset( $info['extension'] )) ? $info['extension'] : '';
//Save the file
$pathName = PATH_DOCUMENT . G::getPathFromUID($appUid) . PATH_SEP;
$pathFileName = $appDocUid . '_' . $docVersion . '.' . $extAux;
copy($pathFile, $pathName . $pathFileName);
//Update
$result = $appDocument->update([
'APP_DOC_UID' => $appDocUid,
'DOC_VERSION' => $docVersion,
'APP_DOC_TAGS' => 'INPUT',
'APP_DOC_FIELDNAME' => $file['APP_DOC_FIELDNAME']
]);
//Remove the old submitted file completely from file system
unlink($pathFile);
$fileCount++;
}
return $fileCount;
}
} catch (Exception $e) {
throw $e;
}
}
Then add a trigger to your process like the following:
Code: Select allif (isset(@=SpecFiles) and !empty(@=SpecFiles)) {
$inputDocumentUid = '11252938559a77b742fb041094562909';
PMFAssociateUploadedFilesWithInputFile($inputDocumentUid, @=SpecFiles,
'', @@APPLICATION, @@USER_LOGGED, @@INDEX);
};
Where "SpecFiles" is the variable associated with a MultipleFile control. Set this trigger to execute after the DynaForm containing the MultipleFile control.
Here is a sample process showing you how to do it:
(28.13 KiB) Downloaded 316 times