Skip to content

Adding Print Support to the Order View

Here, you will learn how to add print options to a data entry view, instead of a Report View, from which reports are usually launched.

Adding a Report to an Entry View

If the order entry view is not currently loaded, you should open this view.

When the order entry view was created, we added a "Print Order" button. Currently, that button serves no purpose. We will now add the code required to make this button actually print the current order. To do this, we must do the following:

  • Add a message (and its supporting procedure) to the order view which will print the report. It will do this by sending a message to the report object, passing the order number to print.
  • Add code to the print button to start the report process.
  • Add code to the view to disable the print button when no order exists.
  • Add a method to the view that prints the current order.

Adding a Procedure to the Report View that Accepts an Order Number and Starts the Report

Add the following code to OrderReport.rv just above the oReport object:

Procedure PrintOrder Integer iNum
    Set Value of oSelStart to iNum
    Set Value of oSelStop to iNum
    Send StartReport
End_Procedure

This procedure accepts an order number, sets the values of start and end Forms to that order number to constrain the report to just that order, then starts the report by calling StartReport.

Adding a Procedure to Print the Order

Add the following code at the bottom of Order.vw:

Register_Object oOrderReport
// Print the current order. This message will be sent by the print button
Procedure PrintCurrentOrder
    Integer hDD iNum
    Get Server to hDD // This will be the OrderHeader DD
    If (HasRecord(hDD)) Begin // Only do this if record exists
        Get Field_Current_Value of hDD Field OrderHeader.Order_Number to iNum
        Send PrintOrder of oOrderReport iNum
    End
End_Procedure

The PrintCurrentOrder procedure is our interface for printing a report. The print button will send this message to the order entry view. If we wanted, this message could be sent via other means as well. For example, we could assign an accelerator key (e.g., Alt+P) to this method by adding the following line to the view’s code area:

On_Key Key_Alt+Key_P Send PrintCurrentOrder

This procedure needs to do the following:

  1. Get the object ID of the OrderHeader data dictionary.
  2. If the OrderHeader dictionary contains a current order (i.e., if the DD’s HasRecord method returns true), it will get the current order number from the Data Dictionary and send the message PrintOrder to the ReportView object (oOrderReport).

Adding Print Support to the "Print Order" Button

Add the following custom code to the oPrintBtn object:

Procedure OnClick
    Delegate Send PrintCurrentOrder // Defined in view object
End_Procedure

When the print button is selected, the message PrintOrder will be called in the button’s parent, the view object.

The delegate command was not really needed, since the button object would not have understood the message and would have delegated the message anyway. The delegate command was used because it makes the programmer’s intent clearer.

Enabling / Disabling the Print Button

When the order view contains an order record, we want the print button to be enabled. When the order view is empty, or the current information is not yet saved, we want the print button to be disabled.

As demonstrated earlier, every time a record is found or cleared, the message Refresh is sent to all data-aware objects. By augmenting this message in one of the data-aware objects, we will be able to enable or disable the print button as needed. Add the following code to the oOrderHeader_Order_Number object:

// Refresh is sent to containers. We will use that to control the print button and only
// enable it when an order exists
Procedure Refresh integer eMode
    Boolean bRec
    Handle hoServer
    Get Server to hoServer
    Get HasRecord of hoServer to bRec
    Set Enabled_State of oPrintBtn to bRec
End_Procedure

As you can see, we are checking to see if the OrderHeader table’s Data Dictionary contains a current record. If a record exists, we enable the button; if not, we disable it.

Note that we could have augmented any of the data-aware controls. We chose the order number control because it was first. Save the Order Entry view.

Next Step

Reviewing Additional Report Samples