Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
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.
#812369
Hi, for the past day, I've been trying to make a script task work after a 1 minute timer event but this specific trigger doesn't work in it (if I reassign the task to myself and execute it, it works great so I don't think there is any fatal error in my trigger..). I used a timer event because the script trigger is pretty long (about 30 seconds) so we don't want the user to wait while populating the database with the excel fields.. I thought about using parallel tasks + timer event of 1 minute to delay the script task to execute so the user won't notice anything

I'm reading an excel calculation file with PHPExcel (it's installed and everything works great). After that, I'm sending the data in this file in my database (119 rows are inserted when i execute the trigger).

Here's the code:
Code: Select all
@@varRevision = 1;
if(@@uploaded_file_id != "")
{
   $uploaded_file_id = @@uploaded_file_id;
   $DOC_VERSION = @@uploaded_file_version;
   $oAppDocument = new AppDocument();
   $oAppDocument->Fields = $oAppDocument->load($uploaded_file_id, $DOC_VERSION);
   
   $ext = pathinfo($oAppDocument->Fields['APP_DOC_FILENAME'], PATHINFO_EXTENSION);
   
   $app_uid = G::getPathFromUID($oAppDocument->Fields['APP_UID']);
   $file = G::getPathFromFileUID($oAppDocument->Fields['APP_UID'], $uploaded_file_id);
   
   $realPath = PATH_DOCUMENT .  $app_uid . '/' . $file[0] . $file[1] . '_' . $DOC_VERSION . '.' . $ext;
   $realPath1 = PATH_DOCUMENT . $app_uid . '/' . $file[0] . $file[1] . '.' . $ext;
   if(file_exists($realPath) || file_exists($realPath1))
   {
      if(!file_exists($realPath) && file_exists($realPath1))
	  {
         $realPath = $realPath1;
	  }
	   @@realPath = $realPath;
      
      require_once('../engine/PHPExcel/PHPExcel.php');
	   
      $excel_file_type = PHPExcel_IOFactory::identify($realPath);
	  @@excel_file_type=$excel_file_type;
      
    if($excel_file_type == 'Excel5' || $excel_file_type == 'Excel2007')
	{
         $excel_reader = PHPExcel_IOFactory::createReader($excel_file_type);
         $excel_reader->setReadDataOnly(true);
		 $excel_reader->setLoadSheetsOnly( array("Global") );
         $excel = $excel_reader->load($realPath);
         $excel_file_creator = $excel->getProperties()->getCreator();
         $excel_file_created = $excel->getProperties()->getCreated();
		  
         
         $excel_sheets_temp = $excel->getSheetNames();
         @=Excel_Sheets = array();
         foreach($excel_sheets_temp AS $key => $row)
		 {
            @=Excel_Sheets[] = array($key, $row);
         }
         
         @@Excel_File_PATH = $realPath;
         @@fileName = $oAppDocument->Fields['APP_DOC_FILENAME'];
         @@fileType = $excel_file_type;
         @@uploader = $excel_file_creator;
         @@dateUploaded = date('Y-m-d', $excel_file_created);
	   
	   $aData = $excel->getActiveSheet()->toArray(null, true, true, true);
	   @@aData = $aData;
	   
	   $queryType = "SELECT ID,NAME FROM QUALTECH_RFQ_CALCULATIONS_TYPES WHERE NAME='QS_CUSTOM'";
	   @@queryType = $queryType;
	   $resultType = executeQuery($queryType);
	   if(!empty($resultType) && count($resultType) > 0)
	   {
		  $idType = $resultType[1]['ID'];
		  $REVISION=@@varRevision;
		  $DATE_UPLOADED=@@dateUploaded;
		  $NAME=@@fileName;
		  $CASE_ID=@@APPLICATION;
		  $queryCalculationSelect = "SELECT * FROM QUALTECH_RFQ_CALCULATIONS WHERE CASE_ID='$CASE_ID' AND REVISION=$REVISION AND CALCULATIONS_TYPES_ID=$idType";
		   @@queryCalculationSelect = $queryCalculationSelect;
		   $resultCalculationsSelect = executeQuery($queryCalculationSelect);
		   if(!empty($resultCalculationsSelect) && count($resultCalculationsSelect) > 0)
		   {
			  $calculationId = $resultCalculationsSelect[1]['ID'];
			  $queryCalculation = "UPDATE QUALTECH_RFQ_CALCULATIONS SET DATE_UPLOADED='$DATE_UPLOADED',NAME='$NAME' WHERE CASE_ID='$CASE_ID' AND REVISION=$REVISION AND CALCULATIONS_TYPES_ID=$idType";
			   executeQuery($queryCalculation);
		   }
		   else
		   {
			   $queryCalculation = "INSERT INTO QUALTECH_RFQ_CALCULATIONS(CASE_ID,REVISION,CALCULATIONS_TYPES_ID,DATE_UPLOADED,NAME) VALUES('$CASE_ID',$REVISION,$idType,'$DATE_UPLOADED','$NAME')";
			   executeQuery($queryCalculation);
			   
			   $queryCalculationSelect = "SELECT * FROM QUALTECH_RFQ_CALCULATIONS WHERE CASE_ID='$CASE_ID' AND REVISION=$REVISION AND CALCULATIONS_TYPES_ID=$idType";
		   $resultCalculationsSelect = executeQuery($queryCalculationSelect);
			   if(!empty($resultCalculationsSelect) && count($resultCalculationsSelect) > 0)
			   {
				   $calculationId = $resultCalculationsSelect[1]['ID'];
			   }
		   }
		   @@calculationId = $calculationId;
		   @@queryCalculation = $queryCalculation;
		   
		   $queryFields = "SELECT CF.ID,CF.NAME,CF.CALCULATIONS_ZONES_ID,CF.CALCULATIONS_JOB_TYPES_ID,CF.CELL FROM wf_workflow.QUALTECH_RFQ_CALCULATIONS_FIELDS AS CF INNER JOIN
QUALTECH_RFQ_CALCULATIONS_TYPES AS CT ON CF.CALCULATIONS_TYPES_ID=CT.ID WHERE CT.ID=$idType";
		   @@queryFields = $queryFields;
		   $resultFields = executeQuery($queryFields);
		   if(!empty($resultFields) && count($resultFields) > 0)
		   {
			   for($i = 1; $i <= count($resultFields); $i++)
			   {
				   $fieldId = $resultFields[$i]['ID'];
				   $zoneId = $resultFields[$i]['CALCULATIONS_ZONES_ID'];
				   $jobTypeId = $resultFields[$i]['CALCULATIONS_JOB_TYPES_ID'];
				   $cell = $resultFields[$i]['CELL'];
				   $letter = preg_replace("/[^A-Z]+/", "", $cell);
				   $number = preg_replace('/[^0-9]/', '', $cell);
				   //$value = $aData[$number][$letter];
				   $value = $excel->getActiveSheet()->getCell($cell)->getOldCalculatedValue();
				   if($value != "" && $value != null)
				   {
					   $queryFieldValueSelect = "SELECT * FROM QUALTECH_RFQ_CALCULATIONS_FIELD_VALUES WHERE CALCULATIONS_FIELDS_ID=$fieldId AND CALCULATIONS_ID=$calculationId";
					   @@queryFieldValueSelect = $queryFieldValueSelect;
					   $resultFieldValueSelect = executeQuery($queryFieldValueSelect);
					   if(!empty($resultFieldValueSelect) && count($resultFieldValueSelect) > 0)
					   {
						  $queryFieldValue = "UPDATE QUALTECH_RFQ_CALCULATIONS_FIELD_VALUES SET VALUE='$value' WHERE CALCULATIONS_FIELDS_ID=$fieldId AND CALCULATIONS_ID=$calculationId";
					   }
					   else
					   {
						  $queryFieldValue = "INSERT INTO QUALTECH_RFQ_CALCULATIONS_FIELD_VALUES(CALCULATIONS_FIELDS_ID,CALCULATIONS_ID,VALUE) VALUES($fieldId,$calculationId,'$value')";
					   }
					   @@queryFieldValue = $queryFieldValue;
					   executeQuery($queryFieldValue);
				   }
			   }
		   }
	   }
	}
  }
}
#812387
amosbatto wrote:Is your server set up to periodically execute the timereventcron.php file? Do you see anything when you manually execute the timereventcron.php file?
| Not exists any record to continue a case, on date "2017-12-01 13:59:28 (UTC +0) so the timer event seems finished. It's just that the trigger won't execute. If I look at the trigger form, my { and } are red (the 2 first) but the closing brackets are there at the end and the code actually execute when I reassign the task to myself. I tried everything but can't figure out why it's happening
#812417
You need to execute timereventcron.php several times. The first time timereventcron.php is executed, it will set the time when the timer event should start. The second time timereventcron.php is executed it will start the timer. The third time it will end the timer event (if past the set time).

Your php.ini and evn.ini files both need to be set to the same time zone.
For example, if your php.ini file is set to:
Code: Select all
date.timezone = America/La_Paz
Then your env.ini needs this line:
Code: Select all
time_zone = "America/La_Paz"
Also make sure that your PM server is using that same time zone for its system clock.

Being the best in the started business is the obje[…]

Winzo is a popular and unique game on the mobile p[…]

Cannot create process using templets

Real details. The problem was solved by effect!

However, it is essential to use it responsibly and[…]