In this step you will create a relationship handler that loads Employees into the instance list when a Department is expanded.
You could have loaded the all the Employees in the hidden filter code together with the Departments, but by using a relationship handler you can improve filter performance by first only adding root or parent objects to the instance list and then dynamically adding the child objects.
1. In the Visual LANSA editor, create a reusable part (for example of type Panel), name it iiiCOREL (iii are your initials), and enter Relationship Handler as the description.
2. In the Source tab change the Begin_Com statement to specify #VF_AC023 as the ancestor. It is the relationship builder Ancestor class.
3. Next add this statement to use and redefine the uAddEntriesFor method:
Mthroutine Name(uAddEntriesFor) Options(*REDEFINE)
Endroutine
The method routine contains predefined parameters.
4. Lastly add this code to load the employee data to the instance list:
#xDepartmentCode := #AKey1
Select Fields(*ALL) From_File(xEmployeeByDepartment) With_Key(#xDepartmentCode)
Signal Event(uAddListItem) Akey1(#xDepartmentCode) Akey2(#xEmployeeIdentification) Visualid1(#xEmployeeGivenNames + " " + #xEmployeeSurname) Visualid2(#xEmployeeIdentification) Acolumn1(#xEmployeeStreet) Acolumn2(#xEmployeeCity) Acolumn3(#xEmployeeState) Acolumn4(#xEmployeePostalCode) Businessobjecttype(#TargetType)
Endselect
Your code now looks like this:
5. Compile the reusable part.
6. Display the Framework.
7. Display the Properties of the Departments business object.
8. In the Relationships tab select the Employees business object.
9. In the Relationship Handler field, type in the name of the relationship handler iiiCOREL, and tick the Use a Reusable Part check box.
10. Close the Departments Properties.
11. Save and restart the Framework.
12. Select the Departments business object in the iiiHR application.
13. Expand a department in the instance list, and then the employees in the department.
The employees in each department you expand are loaded dynamically.
Note that only the employee's name and identifier are shown in the list. In the next step you change the instance list to show additional columns for the employees.