View RSS Feed

Development Team Blog

Visual Report Writer and The Web (VI)

Rate this Entry
Blog number six in this category about Visual Report Writer and the web integration. I will talk about the next report that you can find on the Live Demo website (European Server, USA server) named Credit and Balances Overview. If this is the first blog you read I encourage you to read the five other blogs (1: The Solution, 2: Invoices Report, 3: The Cleanup, 4: The CustomerList and 5: The OrderList). Between the fourth and the fifth blog we have been able to release the Alpha I version of Visual Report Writer 3.0 and the 2.1+ Library only setup. The latter one is needed to make the web reporting using the 17.1 DataFlex Web Framework easy and look like at the demo website.

The Report
The report uses the DataFlex embedded database, the same database as is used for the WebOrder workspace of version 17.1. The tables Orderhea and Customer are in use and a normal relationship between orders and customers is in force. The special features in this report are three calculated columns (functions) that concatenate customer details, calculate the difference between credit_limit and balance and display the number of years that is between the current date and the order date. Further the report creates a new page for each customer.

The Integration
At integration level there are two cWebView components using the report. One creates a PDF when browsing through the customers and one makes it possible to export the report to a mult-page TIFF file and download this to your computer.

The PDF report
In the cWebView component that creates a PDF we need to focus on how this is triggered as the PDF creation and displaying it in an iFrame is already covered in other blogs in the serie. As you can see the report executes automatically when browsing through the customers in the database. It also shows you how fast Visual Report Writer can do this (and I promise 3.0 will be faster!). And keep in mind that the report is exported to file at the web server and downloaded to the browser. BTW, you will see Google Chrome display the report faster than Firefox as the build in PDF viewer of Chrome is faster and does not convert the PDF to HTML which is done by FireFox.

To trigger the report creation we made use of the OnPostFind event of the datadictionary class. Here is the code:
Object oCustomer_DD is a cCustomerDataDictionary
    Procedure OnPostFind Integer eMessage Boolean bFound
        Boolean bSyncing bHasRecord

        Forward Send OnPostFind eMessage bFound

        Get AppSynching of ghoWebApp to bSyncing
        If (not (bSyncing)) Begin
            Get HasRecord to bHasRecord
            If (bHasRecord) Begin
                Send GenerateReport of oReport
            Else Begin
                Set psUrl of oViewer to "about:blank"
The only tricky difference between above code and a Windows project that can use the same event (version 17.0 and higher) is the AppSynching check. The report should not be generated when the application is synchronizing.

The report selection is done in the OnInitializeReport event of the cVRWReport object. It takes the current displayed customer number (WebGet) and adds a filter to the report based on this information.
Procedure OnInitializeReport
    Integer iCustomerId

    WebGet psValue of oCustomerCustomer_Number to iCustomerId

    Send RemoveAllFilters C_USEMAINVRWREPORTID
    If (iCustomerId <> 0) Begin
        Send AddFilter C_USEMAINVRWREPORTID "{Customer.Customer_Number}" C_VRWEqual iCustomerId
The TIFF report
In order to show you that reports are not limited to PDF generation, display and handling and that Visual Report Writer can export to other file formats this cWebView was added. A TIFF file is a image file format that allows multiple pages in one file. Make sure you have an image viewer that support this if you want to see this. Where the PDF report view automatically generates the report this view let you decide. You first browse to a customer, lookup its information and then press the "TiFF download" button. When you press this only difference sits in the GenerateReport method.
Procedure GenerateReport
    String sReportId sFile sUrl
    VRWImageExportOptions ImageExportOptions
    Boolean bCanceled

    Get OpenReport to sReportId
    If (sReportId <> "") Begin
        Get DefaultImageExportOptions to ImageExportOptions
        Set pImageExportOptions to ImageExportOptions
        Get ReportCacheFileName ".tiff" to sFile
        If (sFile <> "") Begin
            Send ExportReport C_VRWImage sFile    
            Get pbCanceled to bCanceled
            If (not (bCanceled)) Begin
                Get DownloadURL of ghoWebResourceManager sFile to sUrl
                If (sUrl <> "") Begin
                    Send NavigateToPage of oWebApp sUrl btCurrentWindow

        Send CloseReport sReportId
The differences are:
  • .tiff export filename (instead of .pdf so-far)
  • VRWImageExportOptions structure in use (instead of VRWPDFExportOptions)
  • DefaultImageExportOptions instead of DefaultPDFExportOptions
  • C_VRWImage parameter for ExportReport instead of C_vrwPDF
  • NavigateToPage instead of setting the psURL
The browser will in most cases download the tiff file to your computer as TIFF file display in a browser requires a special plug in (if available).

I hope that this sixth blog sets you on the path of using Visual Report Writer in the web report world. More blogs will follow.