Contents Hide
Reports may be generated server-side on BrightServer instances using BrightServer Scripts and methods. This will create PDF reports on the server's file system using BrightXpress' Report framework. These reports may then be used for other back-end processes, or synchronised back to devices, typically with the externalBlob data type.
BrightXpress' Report framework, also found in BSP projects, consist of Table, Query and Report elements. With these defined, the reports may be generated via BrightServer script. These concepts are described in the sections below.
Reports will display a set of data on a set of tables defined for the project. These tables are defined in the Tables node of the BEP, and creating or tapping on tables under this node will open Table Editor, as in BSP projects. These tables are also used when defining sync point sources/destinations, and mappings for the server.
For more information, please refer to BrightServer > Tables, and BrightBuilder > Tables sections of this document.
For BrightServer reports, by default these tables will be read from the server's default data source, defined in the BEP's sync panels. If a default data source is not found, the report generation will fail in the BrightServer script. If another data source is to be used, the setDataSource() method may be called prior to generating the report.
The set of data from the tables in the project are defined by Queries, and may be on set or parameterised conditions for table data. Queries should be limited to standard or advanced types for BrightServer reports. These queries may be found under the Queries node of the BEP project, are defined exactly the same way with the BSP Query Editor, and are even able to be directly copied and pasted to/from existing BSPs.
For more information on queries, please refer to the BrightBuilder > Queries section of this document.
The Reports node in BEPs detail the layout of reports which the server may generate. Multiple reports may exist for a BEP project, and tapping reports defined under this node will open the report's layout for editing in the Report WYSIWYG editor. This editor is also laid out the same way as in BSPs, featuring drag and drop positioning of fields in the layout. Reports may also be copied directly to/from BSP projects.
Briefly,
The Body section represents a single record in the query the report is on. A query which returns 50 records will have 50 body entries in the resulting report. In this section, Data Fields may be laid out to display text or image data within the record's columns.
Header and Footers for the report or pages are optional sections which may be used for presentation purposes in the report. In addition to this, data fields may be added into these sections to display column functions, and running totals across all records in the report. The Report.GetPageNumber() method may be assigned to these data fields to display the page number in these sections.
Records from the query may additionally be Grouped, configured via the report's Data tab. This will segment sets of records based on matching columns in the report, and create Group Header and Group Footer sections in the report layout. These headers and footers may contain their own presentation information, including grouped functions and running totals.
Parameters for the report query, and variable fields to display in the report may also be included, and are set before the Report is generated.
For more information on configuring reports in BrightBuilder, please refer to the BrightBuilder > Reports section of this document.
Despite
displaying in the WYSIWYG, not all fonts are available, and may not
appear as rendered in the resulting PDF report. With fonts, only Helvetica,
Courier and Times are offered, and fonts will render in these styles
if their Font Family contains these names. Otherwise, the default
font will be Helvetica.
With Table, Query and Report definitions in the BEP project, a Report object may be instantiated via the ScriptSession.createReportObject() method in a BrightServer Script to configure and print the PDF report. Parameters for this object may be set via the setQueryParam() method, while variables may be set with setVariable(). If the data source to be queried isn't the default in the BEP, the setDataSource() method may be called to specify the data source.
After this, the printToPDF() method may be called naming the report and file output path. Once complete, the Report object may be closed with the close() method.
The following example will print the "rptTest" report to file ("C:\Temp\temp.pdf") after setting a set of variables and parameters:
var rptTest = ScriptSession.createReportObject();
try
{
var strVal = "String";
var blnVal = true;
var dblVal = 2.33;
var intVal = new Integer(42);
var dtVal = Calendar.getInstance();
dtVal.add(Calendar.MONTH, -12);
rptTest.setVariable("Variable1", strVal);
rptTest.setVariable("Variable2", blnVal);
rptTest.setVariable("Variable3", intVal);
rptTest.setVariable("Variable4", dblVal);
rptTest.setVariable("Variable5", dtVal.getTime());
rptTest.setVariable("Variable6", null);
rptTest.setQueryParam("pDateGtEq", dtVal.getTime());
rptTest.setPageSize (210, 297);
rptTest.setDataSource("SyncPoint1_Database3");
rptTest.printToPDF("rptTest", "C:\\Temp\\temp.pdf");
}
catch (error)
{
ScriptSession.logError("Error generating PDF file : " + error) ;
}
finally
{
if (rptTest !== null)
{
rptTest.close();
}
}
Please note the following:
Page size may be set with the setPageSize() method - if this method is unspecified, the report will be generated as A4-sized, i.e. with Width/Height as 210mm x 297mm.
If parameters or variables are not explicitly set, printToPDF() will fail.
Default data source is ignored as setDataSource() is used. The data source used is 'Database3' which should be located in 'SyncPoint1'.