Share ideas, ask questions, and get feedback about developing for ProcessMaker
Forum rules: Please post new questions under "Developing processes & programming" for ProcessMaker 2 or 3.
By lmherrera
#782798
Hi, Im trying to extract from a grid, in a specific field, the uniques values. In other words, make a distinct from a column. To later insert them into a listbox

In order to do this, I define a javascript function like this:
Code: Select all
function ExtractUniqueValues()
{
  //declare an empty array
  var arraylistResponsables = new Array();
  
  //count the grid rows
  var filasGrid = Number_Rows_Grid("dgvActividades", "Responsable");

  
  //loop the grid to check each row 
  for (var i = 1; i <= filasGrid ; i++) 
  {
    //variable that contains the value of each cell in every loop
    var elementoFila = getGridField("dgvActividades", i, "Responsable").value;

    
    //loops the array to compare each value with the array item
    //if it is empty, inserts it
    if (parseInt(arraylistResponsables.length)==0)   
    {
      arraylistResponsables[arraylistResponsables.length] = elementoFila;
    }    
    else    
    {       
      for (var j= 0; j<= arraylistResponsables.length; j++) 
      {
        
        //compare the values
        if( elementoFila != arraylistResponsables[j] )
        {
          //if the value doesnt exist in the array, the value is added to the array
          arraylistResponsables[arraylistResponsables.length] = elementoFila;
        }
       
      }
      
    }
   
  }
    
    
  //loop the array to fill the listbox
  for (var ind = 0; ind <= arraylistResponsables.length; ind++) 
  {
    var objListaResponsable;
    objListaResponsable = getField('lstResponsables');
    
    opc = new Option(arraylistResponsables[ind]  ,arraylistResponsables[ind]  );
    
    eval(objListaResponsable.options[objListaResponsable.options.length]=opc); 
  }
  
}
ExtractUniqueValues();
Due the limitation of PM to debug, i havent found the error, i just know that the execution stops in the line:
Code: Select all
 else    
    {       
      for (var j= 0; j<= arraylistResponsables.length; j++) 
      {

I need help to identify the error, or if you know any other way to do this.

Any help is welcome... Thanks...

Regards
By OscarBarrientos
#782896
Hi lmherrera,

You can execute a trigger to make a distinct from rows or columns and save the results in an array to be used in a list box or other fields.
For example a distinct from rows:
Code: Select all
//Create the array of results
@=result = array();  
@=result[1]=array(
      'FIELD1'    => @=products[1]['FIELD1'],
      'FIELD2'    => @=products[1]['FIELD2']
   );  
  $aux=0;
for ($i = 1; $i < count(@=products); $i++) {

   $a1=@=products[$i+1];
//Define how many rows are in our new array
@@limit=count(@=result);
     $aux=0;
  for ($j = 0; $j < @@limit; $j++) 
   {
      $a2=@=result[$j+1];
//compare if they are equal 
     if ($a2 == $a1){$aux=1;} 
   }
//add the row if it is not repeated
  if($aux==0){@=result[$i+1]=array(
      'FIELD1'    => @=products[$i+1]['FIELD1'],
      'FIELD2'    => @=products[$i+1]['FIELD2']
   );
   }
}
  
To learn more about accessing grid with php:
http://wiki.processmaker.com/index.php/ ... s_with_PHP
To learn more about accessing grid with javascript:
http://wiki.processmaker.com/index.php/ ... JavaScript

Hope it helps,

Regards

ICO software script is a pre-made program for crea[…]

A crypto exchange script is a pre-designed softwar[…]

So I recently bought an addmotor Ebike which of co[…]

A crypto casino clone script is a ready-made softw[…]