Populate & Sort the DropDown Box


/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
/* This example would be used when the values of the DropDown need to be changed due   */
/*    to another value on the page changing.                                           */
/* MODIFY this example for a normal situation where the DropDown box does not need     */
/*    to be updated once the page is displayed for the first time.  In this normal case*/
/*    you would call the code from RowInit, and not loop through the rowset that the   */
/*    DropDown belongs to, but instead would do all the code without the first FOR Loop*/
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/

Local Rowset &RS, &RS_DDvalues;
Local Field &DD_Fld;
Local number &i, &j, &MyChoiceOption, &HowManyTABs2Add;
Local string &FILL_Clause, &FV, &DropDownDisplayText;

Function Populate_My_DropDown_In_FieldValue_Order

   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
   /* Get a handle on the Rowset containing the record that the DropDown field is in   */
   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
   &RS = GetLevel0()(1).GetRowset(Scroll.MY_SCROLL_RECORD);

   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
   /* Rowset &RS_DDvalues is used in the STYLE NUMBER 2 section below                  */
   /* Create the Rowset to retrieve values for populating DropDown at runtime          */
   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
   &RS_DDvalues = CreateRowset(Record.PSXLATITEM);

   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
   /* Build the FILL statement to retrieve the field name that you want                */
   /*   For this example, the FIELDNAME of AE_PROCESS_STATUS is hard coded             */
   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
   &FILL_Clause = "WHERE FIELDNAME = 'AE_PROCESS_STATUS' AND EFF_STATUS = 'A' ";
   &FILL_Clause = &FILL_Clause | "AND %EffdtCheck(PSXLATITEM, FILL, :1)";

   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
   /* Now call the FILL method to populate the Rowset                                  */
   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
   &RS_DDvalues.Fill(&FILL_Clause, %Date);

   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
   /* Sort &RS_DDvalues whichever way you would like (FIELDVALUE, EFFDT, XLATLONGNAME, */
   /*   XLATSHORTNAME, LASTUPDDTTM, LASTUPDOPRID, etc.) This will determine what order */
   /*   the entries display in your DropDown box when using STYLE NUMBER 2             */
   /*   For this example we will sort on the FIELDVALUE field                          */
   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
   &RS_DDvalues.Sort(PSXLATITEM.FIELDVALUE, "D");

   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
   /* Now loop through each row in the scroll area to set each of the DropDown boxes   */
   /*   with the desired values                                                        */
   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
   For &i = 1 To &RS.ActiveRowCount

      /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
      /* Get a handle on the DropDown box for you to populate with your own values     */
      /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
      &DD_Fld = &RS(&i).MY_SCROLL_RECORD.MY_DROPDOWN_BOX_FIELDNAME;

      /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
      /* Only necessary to call the ClearDropDownList method if the DropDown has been  */
      /*   previously filled using the AddDropDownItem method.  When this method is    */
      /*   called, the DropDown reverts back to the xlat values or prompt table values */
      /*   (as set up in the Application Designer) unless overridden again by calling  */
      /*   the AddDropDownItem method.                                                 */
      /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
      &DD_Fld.ClearDropDownList();

      /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
      /* Since the DropDown is sorted alphabetically, you must fool the DropDown into  */
      /*   thinking that the text that starts with a Y comes alphabetically before     */
      /*   the text that starts with the M.  How do you do that?  By adding two TAB    */
      /*   characters before the first DropDown value and adding 1 TAB character before*/
      /*   the second DropDown value.  TAB characters are not displayed in the DropDown*/
      /*   box even though they exist in the value.                                    */
      /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/

      &MyChoiceOption = 1;  /* For illustration purposes only - hard code vs dynamic   */

      If &MyChoiceOption = 1 Then
         /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
         /* USE STYLE NUMBER 1 WHEN PLACING THE VALUES DIRECTLY IN CODE                */
         /*    "CODE1", "CODE2", OR "CODE3" will be the values stored in the Database  */
         /*    when the page is saved                                                  */
         /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
         &DD_Fld.AddDropDownItem("CODE1", Char(9) | Char(9) | Char(9) | "YOUR 1st VALUE");
         &DD_Fld.AddDropDownItem("CODE2", Char(9) | Char(9) | " 1 in the middle");
         &DD_Fld.AddDropDownItem("CODE3", Char(9) | "MY LAST VALUE");
      End-If;

      If &MyChoiceOption = 2 Then
         /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
         /* USE STYLE NUMBER 2 WHEN CREATING THE VALUES AT RUNTIME (SETUP TABLE, ETC)  */
         /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
         /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
         /* Loop through each row returned from PSXLATITEM and add to the DropDown box */
         /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/

         For &j = 1 To &RS_DDvalues.ActiveRowCount;
            /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
            /* Get the field value that is the first parameter of AddDropDownItem      */
            /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
            &FV = &RS_DDvalues(&j).PSXLATITEM.FIELDVALUE.Value;

            /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
            /* Get the Text that you want to display in the DropDown box               */
            /*   For purposes of this example, the field XLATLONGNAME is what will be  */
            /*   displayed on the page.                                                */
            /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
            &DropDownDisplayText = &RS_DDvalues(&j).PSXLATITEM.XLATLONGNAME.Value;

            /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
            /* The first row to display must have the most TAB characters, while the   */
            /*    last row must have the least number of TAB characters. You can       */
            /*    correctly know how many TAB characters to place on the first line by */
            /*    taking the number of rows in rowset &RS_DDvalues, adding 1 to that   */
            /*    number and then subtracting how many rows have already been processed*/
            /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
            &HowManyTABs2Add = 1 + &RS_DDvalues.ActiveRowCount - &j;

            /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
            /* Now you need to add the correct number of TAB characters before the     */
            /*   text you will be displaying. Do this by using the repeat function     */
            /*   (Rept) along with &HowManyTABs2Add which was determined above         */
            /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
            &DropDownDisplayText = Rept(Char(9), &HowManyTABs2Add) | &DropDownDisplayText;

            &DD_Fld.AddDropDownItem(&FV, &DropDownDisplayText);

         End-For;

      End-If;

   End-For;

End-Function;
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • email
  • LinkedIn
  • Suggest to Techmeme via Twitter
  • Technorati
  • Twitter
  • Wikio IT