Step 5 Use the Switch History to Return to the Original Business Object

Visual LANSA Framework

Step 5. Use the Switch History to Return to the Original Business Object

In this step you will use the switch history to allow the end-user to return to the Sections business object from where they initiated the switch.

1.   Open the Employees’ Details command handler iiiCOM03.

2.   Display the Common Controls tab in the Favorites tab and drag a push button under the Save button.

3.   Make the caption of the button Back.

4.   Make the name of the button BACK_BTN.

5.   Add a Click event for the button.

6.   In the 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

#avframeworkmanager.avSwitch To(BUSINESSOBJECT) NAMED(#ff_objnme) EXECUTE(#ff_cmdnme)  Caller(#com_owner)

 

ENDROUTINE

 

  • When you want 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. 
  • Again, remember that you don’t want to hard code the component name, which is why avobjecttype (business object name) and avcommandtype (command name) where 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 code above, the business object was retrieved into the #ff_objnme 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.   Now compile the command handler.

 

You are now ready to test the switch history:

8.   In the Framework select a section from the Department Sections business object.

9.   Select an employee from the Sections’ Details command handler.

10.   Display the details of the selected employee by clicking on the Details button.

11.   On the Details command handler of the Employees business object click on the Back button to return to the Sections business object.