Step 7 Add Drop Down for Skill Code optional

Visual LANSA

Step 7. Add Drop Down for Skill Code (optional)

FRM085 - Update from a Grid

From LANSA V12 is a new field visualization option: Dynamic Picklist. This enables a simple Reusable Part component to be created that populates a picklist from a table file such the skills table (SKLTAB). This reusable part can then be attached to the dynamic picklist visualization for the skill code, such as a combo box.

This step simply illustrates a Dynamic Picklist as a solution. See the Visual LANSA Developer Guide for full details and examples.

What is a Reusable Part?

A reusable part is a component which either extends PRIM_PANL, meaning it is a visual panel or extends PRIM_OBJT, meaning it is a hidden component which is invoked to 'do something'.

1.  Create a New / Reusable Part / Object called iiiVIS01 – Skills Picklist. Paste the following code into it and compile it:

Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_OBJT *implements #Prim_dc.iDynamicPicklist)
Mthroutine Name(Load) Options(*redefine)
#Picklist.RemoveAll
Select Fields(*all) From_File(skltab)
#Picklist.Add( #skilcode #skildesc )
Endselect
Endroutine
End_Com

 

Note:
  • *implements Prim_DC.iDynamicPicklist
  • iDynamicPicklist allows a visualization reusable to load the picklist at runtime.
  • Load method is executed during initialization and any time a monitored value or context changes. This picklist instance is received via the Picklist map. Your method routine Load Options(*Redefine) will contain:

    Define_Map For(*input) Class(#PRIM_PKLT) Name(#Picklist) Pass(*BY_REFERENCE)
 

  • The instance of the picklist is maintained at runtime meaning that you must clear the list if new data is required.

2.  Copy the field SKILCODE to create a new field iiiSKILCODE.

a.Copy rules and triggers and Help text.

b.Open the new field in the editor.

c.Select the Visualization tab.

d.Insert a New Dynamic Picklist

3.  Select your reusable part (iiiVIS001) in the Repository Find dialog and click OK.

4.  Select the VisualPicklist in the FieldParts list. Lengthen the combo box (which will display Skill Description) and change its DefaultVisual property to true.

5.  Save and close your field definition.

6.  You will now change the SKILLS grid second column to use iiiSKILCODE, and add code to set up its value and use the correct value when updating the Personnel Skills file from the SKILLS grid.

a.  If necessary open form iiiUpdFromGrid in the editor.

b.  Change the SKILLS grid column 2 to use iiiSKILCODE.

Define_Com Class(#PRIM_GDCL) Name(#GDCL_2) Displayposition(1) Parent(#SKILLS) Readonly(False) Source(#iiiSKILCODE)

c.  In the SKILLS subroutine, set up field iiiSKILCODE before adding an entry to grid SKILLS.

. . . .

#iiiskilcode := #skilcode

Add_Entry To_List(#SKILLS)

. . . .

d.  In the SAVE.Click routine, set up field SKILCODE after each entry in the SKILLS list is read:

. . .

Selectlist Named(#SKILLS)

#skilcode := #iiiskilcode

. . .

7.  Select the Design tab. Select the column heading for the Skill Code column in the SKILLS grid and change its UsePicklist property to true.

     Right click on the Skill Description column heading and use the context menu to Delete Component. This column  is no longer necessary.

8.  Compile and test your form. The Skill Code column (which is ReadOnly false) displays the current skill description for each row.

9.  Click on any cell in the Skill Code column to display a combo box containing all entries from the Skills Table (SKLTAB):

     You can select a new value to change the employee skill. However, your save logic expects skill code cannot be changed (employee skill file is keyed on employee number and skill code).

10. In this step you will control whether the skill code column is read only. For existing skill entries it should be ReadOnly = True. For the five blank entries, skill code column should be ReadOnly = False

a.  Change the SKILLS subroutine, To set column 2 ReadOnly= True, using the following code, after each entry is added:

. . .

Add_Entry To_List(#SKILLS)

#skills.cell<#skills.currentitem.entry 2>.readonly := true

. . . .

     As always, F2 Features help will enable you to find the information you need about the Grid component.

     The cell property is used like this:

#skills.cell<row column>

b.  Change iiiSKILCODE to *blanks, before five blank entries are added. The skills combo box will now show blanks initially.

. . .

#skllist := *default

#iiiskilcode := *blanks

Begin_Loop To(5)

. . .

11. Compile and test your form. For an employee with existing skills you change grade, comment and date acquired only. Use one of the five blank rows to add a new skill. The skill code combo box visualization allows a valid skill to be selected.