Step 6. Use the Switch History to Return to the Original BO
VFW104 – Simple Keyed Collections
In this step you will change the Employee Details command handler to use the switch history to allow the end-user to return to the Departments business object from where they initiated the switch.
1. Open the Employees'
command handler iiiVFW06.2. Drag a push button below the
button.3. Make the Back to Sections.
of the button4. Make the BACK_BTN.
of the button,5. Create a
event for the button.6. In the
event add this code so that when the users click on the button, they will be switched back to the business object from which they came:EVTROUTINE HANDLING(#BACK_BTN.Click)
define field(#ff_objnme) TYPE(*CHAR) LENGTH(32) DESC('Object Name')
define field(#ff_cmdnme) TYPE(*CHAR) LENGTH(32) DESC('Command Name')
* Determine the business object name to switch to
#avFrameworkManager.avrestorevalue WithID1(SWITCH_HISTORY) WithID2(#com_owner.Avobjecttype) WithID3(#com_owner.Avcommandtype) WithID4(OBJECT_NAME) ToAValue(#ff_objnme)
* Determine which command within the business object to switch to
#avFrameworkManager.avrestorevalue WithID1(SWITCH_HISTORY) WithID2(#com_owner.Avobjecttype) WithID3(#com_owner.Avcommandtype) WithID4(COMMAND_NAME) ToAValue(#ff_cmdnme)
* Perform the switch
* Retruns to Departments / Details
#avframeworkmanager.avSwitch To(BUSINESSOBJECT) NAMED(#ff_objnme) EXECUTE(#ff_cmdnme) Caller(#com_owner)
ENDROUTINE
To send the user back to the component from which the switch occurred:
- You need to look at the switch history on the virtual clipboard. Remember that you need to retrieve both the business object and the command to which you need to return. That requires retrieving two values from the virtual clipboard.
- The code first retrieves the OBJECT_NAME or business object value and then the COMMAND_NAME or command value.
- Remember that you don't want to hard code the component name, which is why (business object name) and (command name) were used as the values to the Withid2()and parameters.
- When you have these two values you can perform another switch to return to the previous component.
In the preceding code, the business object was retrieved into the
field and the command was retrieved into the field. Now you simply use the same technique learned earlier to switch to a business object and execute the command.Your code should look like this:
7. Recompile the iiiVFW06 command handler.
You are now ready to test using switch history:
8. In the VL Framework, select _Sections and populate the instance list and select a Section with employee images recorded.
9. Double click an employee image in the Employee Images for Section command handler, to display details of the selected employee.
10. On the
command handler of the Employees business object, click on the button to return to the _Sections business object.