Thursday, February 7, 2013

Duplicate row in Grid

Refined version:

/* Check for data duplicates on a grid. */
   Local Row &row1, &row2;
   Local number &r, &r1;
 
   &rs = GetLevel0().GetRow(1).GetRowset(Scroll.grid_table);
 
   For &r = 1 To &rs.ActiveRowCount
   /*Get grid row*/
      &row1 = &rs.GetRow(&r);
      /*once we have a row, we are going to loop through the grid rows and make sure a specific field value is unique*/
      For &r1 = 1 To &rs.ActiveRowCount
         &row2 = &rs.GetRow(&r1);
         /* if this is a different row, and the field_name value matches then throw an error*/
         If &r1 <> &r And
               &row1.grid_table.field_name.Value = &row2.grid_table.field_name.Value Then
            MessageBox(0, "", 0, 0, "Error.  Duplicate values are not allowed.");
         End-If;
      End-For;
   End-For;


Easy to understand version:
/* Check for data duplicates on a grid. */
   Local Row &row1, &row2;
   Local number &r, &r1;
 
   &rs = GetLevel0().GetRow(1).GetRowset(Scroll.grid_table);
 
   For &r = 1 To &rs.ActiveRowCount - 1
   /*Get grid row*/
      &row1 = &rs.GetRow(&r);
      /*once we have a row, we are going to loop through the grid rows and make sure a specific field value is unique*/
      For &r1 = &r + 1 To &rs.ActiveRowCount
         &row2 = &rs.GetRow(&r1);
         /* if this is a different row, and the field_name value matches then throw an error*/
         If &row1.grid_table.field_name.Value = &row2.grid_table.field_name.Value Then
            MessageBox(0""00"Error.  Duplicate values are not allowed.");
         End-If;
      End-For;
   End-For;

Source: 
http://www.compshack.com/peoplesoft/peoplecode/check-for-data-duplicates-a-grid

No comments:

Post a Comment