Announcement

Collapse
No announcement yet.

Programmatically Setting a Fields Items List

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Programmatically Setting a Fields Items List

    Programmatically Setting a Fields Items List

    I have had numerous questions on how a dropdown selection field can be populated programmatically based on some other value. The example below shows how to specify a selection of lab tests based on the lab type chosen. This can be accomplished by setting the objects items property with a list of items. It is important to note that the systems item values list should not be used when doing this.

    For this example I used the following lab types and test values:
    • URINE
      • SPECIFIC GRAVITY
      • COLOR
      • PH
    • HEMATOLOGY
      • HEMAGLOBIN
      • HEMATICRIT
      • RBC
    • SERUM CHEMISTRY
      • BUN
      • CREATININE
      • POTASSIUM
      • CHLORIDE
    First, I create my screen by adding the 3 fields that I need to use, LABTYPE, TESTNAME and LABVALUE. I set the object type to Dropdown Combo for LABTYPE and TESTNAME and left the LABVALUE as a text field.


    Next, I added the following code to the onLostFocus() method for LABTYPE to assign the appropriate values to the TESTNAME field.



    Note: In this example my lists are created in line using {}. This could also be done using a makelist function - see SAS documentation on lists for more info. http://support.sas.com/onlinedoc/913...a000149602.htm

    OnLostFocus();

    Code:
        ** Get current value of lab test to reset **;
          dcl char tempstr=testname.selectedItem;
       
          ** populate labtest selection based on labtype **;
          select(labtype.selectedItem);
              when('URINE') do;
                  testname.items={'Specific Gravity', 'COLOR','PH'};
              end;
              when('HEMATOLOGY') do;
                  testname.items={'HEMAGLOBIN', 'HEMATOCRIT','RBC','WBC'};
              end;
              when('SERUM CHEMISTRY') do;
                  testname.items={'BUN', 'CREATININE','POTASSIUM','CHLORIDE'};
              end;
              otherwise;
          end;
       
       
          ** reset existing test value **; 
          testname.selectedItem=tempstr;
    Issues:
    1. One problem is that when the items property of an object is reset, the field is cleared. So to work around this and retain any existing value that may be in the field, I created a temporary variable to hold the current value. I get the value by getting the objects selectedItem value. Then, after assigning the items, I reset the selectedItem value.

    2. When populating another field or performing an action using a field OnLostFocus() method, the action only occurs when you leave that field. This can cause a issue for the dependant field in that if you load an existing record and never go to and leave the field providing the action, the items will not be populated. To circumvent this, we can force the system to run the action fields OnLostFocus() method by firing the objects _tabOut event. This can be done in the screens OnLoad() method. In this case I use the following code for the LABTYPE field:
    OnLoad();
    Code:
      
    labtype._tabOut();
    Screen Shots
    Below are some screen shots of the results.




    Last edited by dkeesey; 07-14-2009, 02:19 PM.
Working...
X