Step 2 Define a Dynamic Picklist for SKILCODE

VLF Windows Application Development

Step 2. Define a Dynamic Picklist for SKILCODE

VFW090 – Field Visualizations

Fields may have Dynamic Visualizations defined. Visualizations may include:

  • A reusable part which includes logic to Autocomplete the value of a field as an entry is typed.
  • A Dynamic Picklist may be defined with entries retrieved from a file at run time.

     For full details refer to the Visual LANSA Developer Guide.

In this example you will create a Dynamic Picklist for a new field iiiSkillCode which populates a dropdown from the file SKLTAB.

1.  Copy field SKILCODE to create a new field iiiSkillCode, copy rules, visualizations and help text. Open the new field in the editor.

2.  A Dynamic Picklist is implemented via a simple reusable part.

     Create a new Reusable Part / Dynamic Picklist:

     Name: iiiVFW20

     Description: Skill Code Dynamic Picklist

3.  A Dynamic Picklist RP is a non visual component (ancestor PRIM_OBJT) which implements #prim_dc.iDynamicPicklist.

     Implementing iDynamicPicklist allows a visualization reusable to Load the picklist at runtime.

Load - The load method is executed during initialization and any time a monitored value or context changes. This picklist instance is received via the Picklist map. The instance of the picklist is maintained at runtime, meaning that the user must clear the list if new data is required.

See the Visual LANSA Developer Guide for more detailed information about Dynamic Visualizations.

4.  The Load method routine which will populate the picklist from the file SKLTAB when the field component is loaded onto a form or panel, needs to be completed.

     The method routine redefines the Load method in the prim_dc.iDynamicPicklist component.

     Add the following code, after the comment line *Populate the picklist, replacing the supplied code provided

* Populate the picklist
Select Fields(#skilcode #skildesc) From_File(skltab)
#Picklist.Add( #skilcode #skildesc )
Endselect

 

     Note:

     The Load method displays a Define_Map. This is part of the redefined Load method of prim_dc.iDynamicPicklist. The parameter passes a reference to a component PRIM_PKLT, named  Picklist in the Load method.

  • The Picklist.Add method enables your reusable part to add entries to the picklist.
  • The Picklist.RemoveAll clears the picklist.
  • The Load method includes code to clear the picklist.
  • Always use F2 Feature Help to investigate the definition of shipped components such as PRIM_PKLT.

5.  Compile your new reusable part.

6.  The new field iiiSkillCode which you just created, should be open in the editor.

7.  Select the Visualizations tab and use the toolbar button to insert a New Dynamic Picklist:

     A Repository Find dialog is displayed. Select your reusable part iiiVFW20.

8.  Select the VisualPicklist component and increase its width.

9.  Select the VisualPicklist and use the Details tab to change its DefaultVisual property to True.

10. Examine the field source code. Note the DynamicPicklist component definition:

Begin_Com Role(*Dynamic_Picklist #IIIVFW20) Name(#DynamicPicklist) Nomatchaction(Blanks)
End_Com

 

     As with all picklists, dynamic or static, the NoMatchAction property needs to be set to determine what to do in the event of the underlying field value not being found in the picklist. For most situations, ShowValue is probably the best choice.

11. Select the DynamicPicklist item. On the Details tab, change the NoMatchAction property to ShowValue.

12. Save the field definition.

13. Open the Employee Skill Detailer (iiiVFW19) in the editor. You will be making similar change as for field iiiGRADE

a.  Change the SKILCODE component definition to use the dynamic picklist,  iiiSkilcode.VisualPicklist.

Define_Com Class(#iiiSkillCode.VisualPicklist) Name(#iiiSkillCode) Displayposition(1) Left(7) Parent(#DETAIL) Tabposition(1) Top(7)

 

b.  Change the Flow Manager item for SKILCODE, to manage iiiSkillCode

Define_Com Class(#PRIM_FWLI) Name(#FWLI_10) Manage(#iiiSkillCode) Parent(#FWLM_2)

 

c.    Close the Replace dialog.

d.  At the top of the PHBN_SAVE.Click event routine add the following code:

#SKILCODE := #iiiSkillCode

 

e.  In the uShow method routine, add the following code immediately after the FETCH:

#iiiSkillCode := #SKILCODE

 

f.  Switch to the Design tab, and increase the width of Skill Code if necessary.

g.  Compile your Employee Skill Detailer reusable part (iiiVFW19).

14. Execute your Framework and ensure that the correct Skill Code description is shown when an employee skill is selected:

15. Create a new employee skill, using the context menu on the employee skills list view. Notice that the skill code dropdown and grade, initially shows their last value. This is because the fields IIISKILCODE and IIIGRADE are not currently being initialized in the uNew method routine.

16. Add code to uNew to set the new fields to their default value and re-test. Notice that iiiGrade defaults to "Pass" as expected and iiiSkilCode shows blanks, which is its default value, copied from field definition SKILCODE.