WAM060 - Employee Maintenance using Advanced Weblets
1. Create a new WAM:
Name: iiiEmpMaint
Description: Employee Maintenance
Layout Weblet: iiilay01
2. Begin by defining the lists needed to support the main page WebRoutine, ShowPage.
These lists will support Dynamic Select Box weblets for department and section codes.
Your code should look like the following:
Function Options(*direct)
Begin_Com Role(*EXTENDS #PRIM_WAM) Layoutweblet('iiilay01')
* Support web page ShowPage
Def_List Name(#depts) Fields(#deptment #deptdesc) Type(*Working)
Def_List Name(#sects) Fields(#section #secdesc) Type(*Working)
Def_List Name(#employs) Fields((#empno *out) (#fullname *out) (#postcode *out) (#PHONEHME *out) (#PHONEBUS *out)) Type(*Working)
Group_by Name(#emps) Fields(#empno #surname #givename #postcode #phonebus #phonehme)
Web_Map For(*both) Fields((#stdrentry *hidden))
End_Com
3. Define a ShowPage WebRoutine.
Your code should look like the following:
WebRoutine Name(ShowPage)
Web_Map For(*output) Fields((#depts *json) (#sects *json) #employs)
Web_Map For(*both) Fields(#deptment #section)
Case (#stdrentry)
When (= S)
Clr_list #EMPLOYS
Select Fields(#emps) From_File(pslmst1) With_Key(#deptment #section)
#fullname := #surname + ', ' + #givename
Add_Entry To_List(#employs)
Endselect
Endcase
Endroutine
4. Define a method routine BuildDepts to populate list DEPTS.
The routine should:
5. Define a method routine BuildSects to populate list SECTS.
The routine should:
Your new code should look like the following:
Mthroutine Name(BuildDepts)
Define_Map For(*input) Class(#deptment) Name(#i_dept)
Clr_List Named(#depts)
Select Fields(#depts) From_File(deptab)
Add_Entry To_List(#depts)
Endselect
If (#i_dept = *blanks)
Get_Entry Number(1) From_List(#depts)
Else
#deptment := #i_dept
Endif
Endroutine
Mthroutine Name(BuildSects)
Define_Map For(*input) Class(#deptment) Name(#i_dept)
Clr_List Named(#sects)
Select Fields(#sects) From_File(sectab) With_Key(#i_dept)
Add_Entry To_List(#sects)
Endselect
Get_Entry Number(1) From_List(#sects)
Endroutine
6. Invoke these method routines at the end of the WebRoutine ShowPage
Your code should look like the following. New code is shown in red.
. . . . .
#com_owner.BuildDepts I_Dept(#deptment)
#com_owner.buildsects I_Dept(#deptment)
Endroutine
7. The Dynamic Select Box weblet will be set up to invoke a response WebRoutine to re-populate the list SECTS when field DEPTMENT changes.
This will require a WebRoutine, UpdSects defined as follows:
Your code should look like the following:
WebRoutine Name(updsects) Response(*JSON)
Web_Map For(*input) Fields(#deptment)
Web_Map For(*output) Fields((#sects *json))
#com_owner.BuildSects I_Dept(#deptment)
Endroutine
8. Compile your WAM.