Step 3. Add Logic to Switch from Sections to the Employees Business Object
In this step you will add logic to the Sections’ Details 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 is executed in a button click event.
1. Display the Design tab of the Details command handler.
2. Drag a push button from the Common Controls tab on to the right hand panel (PANL_1) on the command handler.
3. Make the Caption of the button Details.
4. Add a Click event for the button.
5. 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 ClearInstancList parameter.
6. 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) Caller(#Caller) Options(*NOCLEARERRORS *NOCLEARMESSAGES)
* Make sure the caller is this component
If_ref #Caller is_not(*Equal_to #Com_Owner)
Return
Endif
Invoke Method(#avFrameworkManager.avAddSwitchInstance) BusinessObjectType(EMPLOYEES) Visualid1(#EMPNO) Visualid2(#SURNAME) Akey1(#EMPNO)
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.
- There is no reason that you couldn’t call the avAddSwitchInstance method repeatedly to place multiple entries into the target business object’s instance list.
Your code should now look like this:
7. Compile the command handler.
8. Test the switching: when you select an employee and click on the Details button on the Sections’ Details Command Handler, the Employees business object should be displayed with the selected employee details.