Step 6. Extend the Details WebRoutine to add new employee skill
WAM060 - Employee Maintenance using Advanced Weblets
In this step you will extend the WebRoutine Details to insert a new employee skill.
- A push button on the Skills tab will refresh the grid with a blank first entry.
- The SKILCODE will now be an input field in the list EMPSKLS and the hidden field SC will no longer be needed.
- The SKILCODE column in the grid will be customized using a Dynamic select box.
- The Dynamic select box will be populated with a list of skills from the table SKLTAB. A new method routine will build this list.
- When the Skills Save button is processed, an employee skill will be inserted if the DATEACQR field is zero
1. Change the definition of list EMPSKLS so that SKILCODE is input capable, removing the hidden field SC. Your code should look like the following:
Def_List Name(#empskls) Fields(#SKILCODE #GRADE #COMMENT #DATEACQ (#dateacqr *hidden) (#empno *hidden)) Type(*Working) Entrys(*max)
2. Delete the definition of field SC and remove all code which refers to it.
3. Define a Group_by SKL_LIST for fields SKILCODE, GRADE, COMMENT, DATEACQ, DATAECQR. This will be used to clear employee skills list fields before adding a blank entry for insert.
4. Define a working list SKILLS containing fields SKILCODE, SKILDESC. This list will mapped for output to populate the skill code Dynamic select box.
LANSA definition statements can be placed anywhere in your code. It is usual to place them at the top of the program code.
Your new code should look like the following:
Group_By Name(#skl_list) Fields(#skilcode #grade #comment #dateacq #dateacqr)
Def_List Name(#skills) Fields(#skilcode #skildesc) Type(*Working) Entrys(*max)
5. Add a new When clause to the Details WebRoutine, that will handle a request from the button to add a blank entry as the first entry in the employee skills list. This will allow insert of a new employee skill.
The logic should be based on the following:
- When = N
Your new code should look like the following:
* add new top row to skills list
When (= N)
#skl_list := *default
Add_Entry To_List(#empskls) After(*START)
Message Msgtxt('Complete new skill in the first list entry')
6. When processing a list entry, a value of zero for Date Acquired (DATEACQR) means the entry is new.
Add the following new logic to the CASE loop, for when STDRENTRY = S.
New code is shown in red.
When (= S)
Selectlist Named(#empskls)
If (#dateacqr *NE *zeroes)
Update Fields(#empskls) In_File(pslskl) With_Key(#empno #skilcode) Val_Error(*next)
Else
Insert Fields(#empskls) To_File(pslskl) Val_Error(*next)
Endif
Endselect
If_Status Is(*okay)
Message Msgtxt('Skills for ' + #empno + ' were changed')
Endif
7. Create a method routine BuildSkills to populate the skills list SKILLS.
a. Clear the list SKILLS
b. Select all records from file SKLTAB and add entries to list SKILLS
c. Position to the first entry
Your code should look like the following:
Mthroutine Name(BuildSkills)
Clr_List Named(#skills)
Select Fields(#skills) From_File(skltab)
Add_Entry To_List(#skills)
Endselect
Get_Entry Number(1) From_List(#skills)
Endroutine
8. Add an output web_map for the SKILLS list to the Details WebRoutine as JSON data. Your code should look like the following:
Web_Map For(*output) Fields((#skills *JSON))
9. Invoke the BuildSkills method at the end of the Details WebRoutine. Your code should look like the following. New code is shown in red.
Endcase
#com_owner.BuildSkillsEndroutine
10. Compile your WAM.
11. Open the Details WebRoutine in the view.
12. Select the Skills tab, and select the Grid weblet. On the
tab use the Ellipsis button for the value to open the dialog. With SKILCODE field selected, select the check box and then click to close the dialog.
13. Drop a Dynamic select box into the Skill Code column. See the image below showing how the editor will highlight the column when the cursor is in the correct position.
Adjust the width of the dropdown so that it can display skill description.
14. Select the Dynamic select box and set up its properties as shown:
|
15. Add a push button with image weblet into the into the single row table below the grid. Set up the button properties as:
|
Adjust the width of the push button to display the caption as single line.
Remove the place holder characters from table cell.
16. Select the Details tab page and then Save your changes. Your Skills tab page should look like the following:
17. Retest your WAM. Select an employee and select the Skills tab. The Dynamic select box for skills should display the correct skill description in each row.