The goal here is to extract a constant portion of a string and use that portion to dynamically create a group on a table. The example will use the sample Classic Models database and attempt to extract the year from the product description. For example a product with a description of "1962 Aston Martin" will be included in a group labeled "1962". This is useful when the text in a field is structured. Leveraging that structure to further organize your table-based reports can make them easier for the users to digest.<br />
<br />
The magic comes in the form of a regular expression. The regular expression parses the Product Name field and places the value for the 4-digit year into backreference 1. That backreference is the value (and the label) that will be used to pull rows into each grouping in the table. Here is the Javascript that processes the RegExp:
var myregexp = /([d]{4}).*/;
var match = myregexp.exec(row["PRODUCTNAME"]);
if (match != null) {
match[1];
} else {
"RegExp Failed";
}
<br />
In this snippet of code, the PRODUCTNAME field is processed and a value for the model year is extracted.<br />
<br />
In this design, you can see this same technique applied in the line chart. The values used for the X-Axis are calculated and applied in the same way.<br />
<br />
The report is parameterized. The following vlaues for the pProductLine parameter will yield good results (the PRODUCTNAME field has values for the year): Classic Cars, Trucks and Buses, Motorcycles and Vintage Cars.<br />
<br />
This report is built on BIRT 2.3.<br />
<br />
Enjoy!