Questions and discussion about using ProcessMaker: user interface, running cases & functionality
#790683
Buena tarde, tengo un proceso que se basa en la consulta de dos procesos dependiendo unas listas desplegables, cabe resaltar que si se selecciona un proceso a consultar el otro no se mostrará.
Lo que quiero saber es si de acuerdo a la consulta puedo exportar en excel mediante un botón puede ser los datos que se estén mostrando en la dynaform.
Es posible?
Mil gracias, en espera de sus comentarios.
#790694
He creado un proceso para mostrarte como hacer esto.
(34.29 KiB) Downloaded 522 times
Aca es el código en un trigger para generar un archivo CSV que puedes importar en Excel u otra hoja de calculo:
Code: Select all
@@csvFilename = '';
@@csvLink = '';

if (isset(@=productsList) and is_array(@=productsList) and count(@=productsList)) {
	$aCsv = array();
	//set the first row in the CSV file to the IDs of the grid fields
	$aColumnHeaders = array_keys(@=productsList[1]);
	$line = '';
	foreach ($aColumnHeaders as $fieldId) {
		$line .= (empty($line) ? '' : ';') . $fieldId;
	}
	$aCsv[] = $line;
	
	//set each data row in CSV file:
	foreach (@=productsList as $aRow) {
	   $line = '';
	   foreach ($aColumnHeaders as $fieldId) {
		   $val = $aRow[$fieldId];
		   if (is_array($val) or is_object($val)) {
			  $val = json_encode($val);
		   }
		   //sanitize CSV data to handle double quotation marks, commas, semicolons, 
		   //spaces and new lines 
		   $val = str_replace('"', '""', $val);
           if (preg_match('/[,;"\n\r]/', $val) or trim($val) != $val) { 
              $val = '"' . $val . '"'; 
           }
		   $line .= (empty($line) ? '' : ';') . $val; 
	   }
	   $aCsv[] = $line;
	}
	
	//create a temporary output file:
	$path = tempnam(sys_get_temp_dir(), "products_") . ".csv";
	file_put_contents($path, implode("\n", $aCsv));
					  
	$inpDocId = '91773886359113840b60ec5038468317'; //set to ID of the Input Document
	//upload temp CSV file to PM:
	@@fileId = PMFAddInputDocument($inpDocId, null, 1, 'INPUT', 'CSV file of products', 
		'add', @@APPLICATION, @%INDEX, @@TASK, @@USER_LOGGED, 'file', $path);
					  
	unlink($filename); //delete temporary CSV file
					  
	if (empty(@@fileId)) {				  
	   $g = new G();
	   $g->SendMessageText("Unable to upload CSV file to current case.", "ERROR");
	}
	else {				  
	   @@csvLink = (G::is_https() ? 'https://' : 'http://') .
		  $_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].'/sys' . 
		  @@SYS_SYS.'/en/neoclassic/cases/cases_ShowDocument?a='.@@fileId;
	   @@csvFilename = pathinfo($path, PATHINFO_BASENAME);
	}
}	
#813694
amosbatto wrote:Para cambiar los nombres de los campos, puedes reemplazar esta línea:
Code: Select all
$aColumnHeaders = array_keys(@=productsList[1]);
por esta:
Code: Select all
$aColumnHeaders = array("Campo 1", "Campo 1 Label", "Campo 2", "Campo 2 Label", "Campo 3", "Campo 3 Label");
Hi Amos,
I try this code in trigger
Code: Select all
$aColumnHeaders = array("Campo 1", "Campo 1 Label", "Campo 2", "Campo 2 Label", "Campo 3", "Campo 3 Label");
but the exported file does not contain the data in grid. It has empty rows for rows in grid (it means if grid in dynaform has 4 rows, the exported file has 4 empty rows).
How should I change the code? If I want exported data separated by tab or semicolon (not comma), what code should be added?
Many thanks.
#813704
Necesitas un array separado para las etiquetas de las columnas así:
Code: Select all
@@csvFilename = '';
@@csvLink = '';

if (isset(@=productsList) and is_array(@=productsList) and count(@=productsList)) {
   $aCsv = array();
   //set the first row in the CSV file to the IDs of the grid fields
   $aColumnHeaders = array_keys(@=productsList[1]);
   $aHeaderLabels = array("Field 1", "Field 1 Label", "Field 2", "Field 2 Label", "Field 3", "Field 3 Label");
   $line = '';
   foreach ($aHeaderLabels as $fieldId) {
      $line .= (empty($line) ? '' : ';') . $fieldId;
   }
   $aCsv[] = $line;
   
  //set each data row in CSV file:
   foreach (@=productsList as $aRow) {
      $line = '';
      foreach ($aColumnHeaders as $fieldId) {
         $val = $aRow[$fieldId];
         if (is_array($val) or is_object($val)) {
           $val = json_encode($val);
         }
         //sanitize CSV data to handle double quotation marks, commas, semicolons,
         //spaces and new lines
         $val = str_replace('"', '""', $val);
           if (preg_match('/[,;"\n\r]/', $val) or trim($val) != $val) {
              $val = '"' . $val . '"';
           }
         $line .= (empty($line) ? '' : ';') . $val;
      }
      $aCsv[] = $line;
   }
   
   //create a temporary output file:
   $path = tempnam(sys_get_temp_dir(), "products_") . ".csv";
   file_put_contents($path, implode("\n", $aCsv));
                
   $inpDocId = '91773886359113840b60ec5038468317'; //set to ID of the Input Document
   //upload temp CSV file to PM:
   @@fileId = PMFAddInputDocument($inpDocId, null, 1, 'INPUT', 'CSV file of products',
      'add', @@APPLICATION, @%INDEX, @@TASK, @@USER_LOGGED, 'file', $path);
                
   unlink($filename); //delete temporary CSV file
                
   if (empty(@@fileId)) {             
      $g = new G();
      $g->SendMessageText("Unable to upload CSV file to current case.", "ERROR");
   }
   else {             
      @@csvLink = (G::is_https() ? 'https://' : 'http://') .
        $_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].'/sys' .
        @@SYS_SYS.'/en/neoclassic/cases/cases_ShowDocument?a='.@@fileId;
      @@csvFilename = pathinfo($path, PATHINFO_BASENAME);
   }
} 

In the rapidly evolving world of online sports be[…]

STEPN integrates social networking and games that […]

Cenforce 150 is a medication used to cope with a c[…]

What's SAP FICO?

Trustworthy and skill-building, each of these actu[…]