How to Create reports with Docx and 4ws.Platform
Reports creation is a common problem to face with, when developing web applications. When designing a report, usually a tool is needed to define the report content and the usage of such tools is not always easy and intuitive. Consequently, specific skills and expertise are required in order to use these products.
The same problem arose also with a Rapid Application Development tool like 4WS.Platform, a product designed specifically to speed up and make it easier the creation of web and mobile applications, having an high level of customization and allowing the creation of applications to users having basic skills.
Which solution can be provided to users in order to make it easy and fast the creation of reports within 4WS.Platform? How to do that in a similar simple way already available in that product for other tasks?
Word processors like Microsoft Word™, Open Office o Libre Office are widespread solutions whose usage is easy and well known by a large amount of users. People know how to use them, for instance to write a letter, compile a bill, an essay or to create a resume, etc.
Why don’t exploit the knowledge of these editors that everyone has and start from that?
These editors procude documents in a docx format, which is based on an XML descriptor easily readable by 4WS.Platform.
The widespread of these tools, the semplicity in the creation of documents and the chance to exploit the XML format behind the scenes easily readable are the main reasons for the adoption of the docx format to use for the document template within 4WS.Platform for the reports generation.
In this way, any user can create document templates using these popular editors, format and organize data as they wish and follow simple rules to create a model to populate and finally publish them inside 4WS.Platform to generate reports.
How to create a docx template
As described in the introduction, a user can create his own template by following a few simple rules, but first of all, he can fill in the template, format the content, define the content layout and focus mainly on the result he wants to reach.
Once defined the “static” content and layout of the template, the user has to focus on the “dynamic” parts of the document, which will be replaced with data provided by the application, when generating the report starting from the template.
Finally, when the template has been deployed within 4WS.Platform, queries have to be defined to feed the report for those parts.
Two kinds of variables written in the docx template are supported by 4WS.Platform. These variables have the following syntax:
the value will be replaced with data retrieved through the execution of the query linked to that part of the template
the description will be replaced with data coming from the query execution and translated according to the language used when generating to the report.
The result is reported in the following images.
In addition to what just described, two types of subreports are supported by 4WS.Platform:
- a ‘table subreport’ used to show a list of records
- a ‘form subreport’, used to show values coming for a single report.
These two subreports have the following syntax:
where ‘table’ is the name assigned to the ‘table subreport’, in order to identify it and, for each column of that subreport, an identifier having this syntax:<td>column1</td> <td>column2</td> …It is always possible to include cells whose content is translated according to the report language, using the tag: ‘tdtranslation‘.
All cells having <td> tag will be replicated for each record read through the execution of query linked to that subreport.
Here it is an example of the result of such a kind of subreport.
where subform is the name assigned to the subreport and whose controls are identified by ‘subcontrol’ tags or ‘subcontroltranslation’ tags, in case of data to translate according to the report language.
How to feed the template
Once the user has defined the template, a query has to be written to provide data to show in the report and for each subreport.
4WS.Platform provides several ways to define those queries, through what is called a ‘business component’: the user can define the SQL query manually or use the automatic query composition provided by the 4WS.Platform feature.
How to configure a report
When the user has defined the template and the queries to feed it, the next step is to configure the report within the “Web Designer” component of 4WS.Platform.
In order to complete the template configuration and make it possible to generate a report, 4 simple steps are needed:
1. Uploading the template
The first step includes the name specification for the report and the selection of a business component to link to the report in order to fill in the main section of the report.
Through this feature, the user can choose the docx template file to upload: it is possible to upload a different file for each language, with the constraint that each of these templates have to share the same structure, so that it is possible to fill in each of them with the same data structure.
The report content could depend on data passed in input to that report. That means that the single SQL query could have variables which should be filled with dynamic data. For each of these variables a parameter can be defined along with the other settings provided when defining the report. These parameters have a data type which can be: text, number or date. They can be used when mapping SQL query variables with ad hoc data.
3. Report fields
Once uploaded the docx template, the file is analyzed and a grid is prompted to the user, showing the fields found inside the template that require a mapping, that is to say, to map to the query fields, in order to fill them in.
For each of these bindings, it is possible to define a predefined data format (text, date, integer, decimal, etc.) or take advantage of advanced formatting methods provided by 4WS.Platform.
In the screenshot reported below, a function named ‘formatNumber’ is used to manage the number format, but it is also available a special function to convert a number to its text representation, expressed in a specific language.
In case the uploaded docx template contained subreports (table or form subreports type), a second grid would show the list of these subreports. Through that grid, the user can bind each subreport with a business component (a SQL query) to use to feed that subreport.
Moreover, for each subreport the mapping between its fields and the query fields must be defined by the user, in the same way done for the main region of the report.
A user can change any part of these report settings any number of times: he can change format settings, mappings or change the template content (e.g. static content) by simply uploading the docx file again.
When the user has completed the report settings, the template could be invoked in order to generate a report starting from it and data coming from the execution of the SQL queries.
A report can be generated by invoking it through a server-side action.
In the simplest case, such an action would simply contain a line of code to generate the report, starting from the docx file location:
utils.generateDocx(reportId, args, langId, path, fileName);
Once the report has been generated (in docx format), it is also possible to convert it in another format, for instance a report in PDF format.
To sum up, a report can be produced on the fly without the need to know how to use ad hoc report editors or pay for costly licenses. You can create report templates in docx format with a simple word processor and through 4WS.Platform automate the report generation.
Thanks to popular text editors able to manage docx file format, any newbie user can create report templates and with the simple and intuitive web interface included in the 4WS.Platform solution anyone can also be able to configure and manage the report generation.
 Microsoft, Encarta, MSN, and Windows are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries.