In this step you will add logic to the Departments command handler to display the details of a selected employee in the Details command handler of the Employees business object.
The switch to the Employees' Details command handler will be executed in a button click event.
1. Display the Design tab of the Details command handler.
2. Drag a push button from the Controls tab on to the right hand panel (PANL_1) on the command handler.
3. Using the Layout ribbon, give the button an Alignment of Top Center. Give it a Top margin of 10.
4. Make the Caption of the button Details.
5. Create a Click event for the button.
6. In the click event add a statement to switch to the Details command handler of the Employees business object.
#avframeworkmanager.avSwitch To(BUSINESSOBJECT) NAMED(EMPLOYEES) EXECUTE(DETAILS) Caller(#com_owner) ClearInstanceList(TRUE)
- The To parameter contains BUSINESSOBJECT to indicate the switch is to a business object (you can also switch to the Framework or an application).
- The NAMED parameter must contain your actual business object name.
- The EXECUTE parameter contains the name of the command to execute.
- You can optionally clear the instance list by specifying the ClearInstanceList parameter.
7. Next add the following event routine which will tell the Employees business object which instance should be displayed based on the value of the employee in the grid:
Evtroutine Handling(#avFrameworkManager.avAddSwitchInstances) Options(*NOCLEARERRORS *NOCLEARMESSAGES) Caller(#Caller)
* Make sure the caller is this component
If_Ref Com(#Caller) Is_Not(*Equal_to #Com_Owner)
Return
Endif
Invoke Method(#avFrameworkManager.avAddSwitchInstance) Businessobjecttype(EMPLOYEES) Visualid1(#xEmployeeIdentification) Visualid2(#xEmployeeSurname.AsNativeString)
Akey1(#xEmployeeIdentification)
Endroutine
- The avAddSwitchInstances event routine is always executed immediately after you execute a switch using the avSwitch method. This event allows you to control what data will be placed in the instance list of the target business object. The component signaling this event is passed in the Caller parameter.
- It is important to only execute the code in this event if the component that signaled this event is the component itself. Therefore you should return from this event routine if the caller is not equal to #com_owner. Notice how the is_not(*Equal_to is used to compare the #Caller and #Com_Owner. You must use this syntax due to the fact that you are comparing the component itself and not a simple string.
- The avAddSwitchInstance method specifies what data to add in the target instance list.
- If required, your code could call the avAddSwitchInstance method repeatedly to place multiple entries into the target business object's instance list.
- Check in the Identification tab of the Employees business object that the User Object Name/Type of the Employees business object is EMPLOYEES, otherwise the switching will not work.
Your code should now look like this:
8. Compile the command handler.
9. Test the switching: when you select an employee and click on the Details button on the Departments' Details Command Handler, the Employees business object is displayed with the selected employee details.


