Tuesday, February 26, 2013

SQL Query to Find Overlapping (Conflicting) Date Ranges


-- 2.1) select date ranges that lie outside [d1, d2] (d2 and end_date are inclusive)
SELECT * FROM <table> WHERE @d2 <  start_date OR  end_date <  @d1

-- 2.2) select date ranges that overlap [d1, d2] (d2 and end_date are inclusive)
SELECT * FROM <table> WHERE @d2 >= start_date AND end_date >= @d1
The above queries are based on Allen's Interval Algebra. The following ASCII art should explain the first query:
       @d1 |--------| @d2       
           .        . |--------| @d2 < start_date
           .        |--------|   @d2 = start_date
|--------| .        .            end_date < @d1
  |--------|        .            end_date = @d1
    |--------|      .            
           .      |--------|     
           |--------|            
           . |----| .            
         |------------|          

Link for more detail input.

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

Monday, February 4, 2013

Displaying image on page

PeopleBooks suggest that you will have to use ImageReference type for your Image control for the field on derived/ work record. Here is the procedure:

To associate an image definition with a field at runtime, the field has to be of type ImageReference. An example of this is referencing a red, yellow, or green light on a page, depending on the context.

To change the image value of an ImageReference field:

1.Create a field of type ImageReference.
2.Create the images you want to use.
These images must be saved in PeopleSoft Application Designer as image definitions.
3.Add the field to a record that will be accessed by the page.
4.Add an image control to the page and associate the image control with the ImageReference field.
5.Assign the field value.

Use the keyword Image to assign a value to the field. For example:

MyRec.MyImageField.Value = Image.IMAGE;