Questions and discussion about using ProcessMaker 2: user interface, running cases and functionality
Forum rules: Please search to see if a question has already been asked before posting. Please don't ask the same question in multiple forums.
#788429
Upload the CSV file to a file field in a dynaform and fire a trigger to parse the file and and insert the information in the file into the database.

In the example below, there is a file field named "csvFile" where the user uploads a CSV file. If unable to open the uploaded CSV file or can't read its data, then an error message is displayed, and the case is redirected to the previous DynaForm with the unique ID "67172619648d67d3d5db8f8066114860" to upload a new CSV file.

Code: Select all
if (!isset(@@csvFile) or empty(@@csvFile)) {
    $mesg = "CSV File is empty. Please upload again.";
    goto uploadAgain;
}
$csvFile = trim(@@csvFile); #assign to PHP variables to insert in query
$caseId = @@APPLICATION;
 
//find the assigned UID for the uploaded file:
$query = "SELECT C.CON_ID FROM CONTENT C, APP_DOCUMENT AD WHERE
   AD.APP_UID = '$caseId' AND AD.APP_DOC_UID = C.CON_ID AND C.CON_VALUE = '$csvFile'";
$result = executeQuery($query);
if (!is_array($result) || count($result) == 0) {
   $mesg = "Error: Unable to find the uploaded file '$csvFile' in the APP_DOCUMENT table.";
   goto uploadAgain;
}
$caseIdPath = method_exists(G, "getPathFromUID") ? G::getPathFromUID($caseId) : $caseId;
$filePath = PATH_DOCUMENT . $caseIdPath . PATH_SEP . $result[1]['CON_ID'] . '_1.' .
   pathinfo($csvFile, PATHINFO_EXTENSION);
$aRecords = file($filePath); //Open the CSV file as an array for each line
 
if ($aRecords === false or !is_array($aRecords) or count($aRecords) < 1) {
   $mesg = "Error: CSV File '$csvFile' is not valid format or does not contain any records.";
   goto uploadAgain;
}
@=expensesGrid = array();
 
//Assume that the first line of the CSV file is data and not column headers.
//Loop through the array and for each record break the line into its individual fields.
for ($i = 0; $i < count($aRecords); $i++) {
   //change to ',' if using commas instead of semicolons in the CSV File
   $aFields = explode(';', $aRecords[$i]);
   //change the fields names to match your grid:
   //Code for inserting the values in database goes here
   );
}
goto endScript;
 
uploadAgain:
   G::SendMessageText($mesg, 'ERROR');
   //change for the unique ID of your DynaForm:
   PMFRedirectToStep(@@APPLICATION, @%INDEX, 'DYNAFORM', '67172619648d67d3d5db8f8066114860');
 
endScript:
Hope this helps.

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[…]