Step 6 Use the Switch History to Return to the Original BO

VLF Windows Application Development

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' Details command handler iiiVFW06.

2.  Drag a push button below the Save button.

3.  Make the Caption of the button Back to Sections.

4.  Make the Name of the button, BACK_BTN.

5.  Create a Click event for the button.

6.  In the BACK_BTN.Click 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 avObjectType (business object name) and avCommandType (command name) were used as the values to the Withid2()and Withid3() 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 #ff_objname field and the command was retrieved into the #ff_cmdnme 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 Details command handler of the Employees business object, click on the Back to Sections button to return to the _Sections business object.