Visual Report Writer and The Web (VI)¶
Blog number six in this category about Visual Report Writer and web integration. I will discuss the next report available on the Live Demo website (European Server, USA server) named Credit and Balances Overview. If this is the first blog you are reading, I encourage you to check out the previous five blogs: 1: The Solution, 2: Invoices Report, 3: The Cleanup, 4: The CustomerList, and 5: The OrderList. Between the fourth and fifth blogs, we released the Alpha I version of Visual Report Writer 3.0 and the 2.1+ Library only setup. The latter is necessary to facilitate web reporting using the 17.1 DataFlex Web Framework, as demonstrated on the demo website.
The Report¶
The report utilizes the DataFlex embedded database, the same database used for the WebOrder workspace of version 17.1. The tables Orderhea and Customer are in use, maintaining a standard relationship between orders and customers. This report features three calculated columns (functions) that concatenate customer details, calculate the difference between credit_limit and balance, and display the number of years between the current date and the order date. Additionally, the report generates a new page for each customer.
The Integration¶
At the integration level, there are two cWebView components utilizing the report. One generates a PDF while browsing through the customers, and the other allows exporting the report to a multi-page TIFF file for download 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 its display in an iFrame have been covered in other blogs in the series. The report executes automatically when browsing through the customers in the database, showcasing the speed of Visual Report Writer (and I promise 3.0 will be faster!). Note that the report is exported to a file on the web server and downloaded to the browser. You will notice that Google Chrome displays the report faster than Firefox, as Chrome's built-in PDF viewer is quicker and does not convert the PDF to HTML, unlike Firefox.
To trigger the report creation, we utilize 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
End
Else Begin
Set psUrl of oViewer to "about:blank"
End
End
End_Procedure
End_Object
The only tricky difference between the 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 occurs in the OnInitializeReport event of the cVRWReport object. It retrieves the currently displayed customer number (using 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
End
End_Procedure
The TIFF Report¶
To demonstrate that reports are not limited to PDF generation, display, and handling, this cWebView was added to allow exporting to other file formats. A TIFF file is an image file format that supports multiple pages in one file. Ensure you have an image viewer that supports this format if you wish to view it. Unlike the PDF report view, which automatically generates the report, this view requires user interaction. You first browse to a customer, retrieve its information, and then press the "TiFF download" button. The only difference lies 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
End
End
End
Send CloseReport sReportId
End
End_Procedure
The differences are:
- .tiff export filename (instead of .pdf previously)
- 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
In most cases, the browser will download the TIFF file to your computer, as displaying TIFF files in a browser typically requires a special plugin (if available).
I hope this sixth blog guides you on your journey to using Visual Report Writer in the web report world. More blogs will follow.