One of the most common questions for people that are new to BIRT is about how to ask data from the DataSet in the report. The question is when building expressions should I use dataSetRow["FIELD"] or row["FIELD"]?
So let me see if I can set the record straight. When data is acquired, it is acquired by a DataSet, so the following query in a JDBC DataSet will create a three field resultset:
select CITY, STATE, COUNTRY
from CUSTOMERS
Any script or expressions written on the DataSet will be written to use the format
row["FIELD_NAME"];
So if we add a computed column to the DataSet called compCityState, the expression would look like this.
Once a computed column is created, you can reference that computed column using the same row syntax. So in the OnFetch method you could add this message to log the value of the computed column.
Packages.java.lang.System.out.println(row["compCityState"]);
The other place that you can access variable on the DataSet is through ReportItem binding. In most cases, this means Table Binding where you have attached a table to a DataSet. In general, when you use BIRT you associate a Table with a DataSet. We say that the Table is bound to the DataSet.
When a DataSet is dragged to the Layout editor, BIRT automatically does the data binding and creates a bound column for each field and computed column in the DataSet. The following shows a table and its Binding.
You will notice that all of the expressions use the term dataSetRow, which means this value is pulled from the DataSet. Now for the tricky bit, any field that is bound to a Table can be used in another table binding. So if we wanted to create a field that has City, State and Country, we could either:
a) go back to the DataSet
b) add a new table binding
When you add a binding to a table you are brought to the expression builder. In this first example, I am creating a table binding that gathers data straight from the DataSet.
Now for a quick test, this should be easy.
Imagine that I change the expression of the CITY expression to look like this, and all else remains the same.
If the values for the row are:
City: Kalamazoo
State: MI
Country: USA
What will a DataItem that is showing rowCityStateZip display?
What will a DataItem that is showing tablCityStateCountry display?
The answers will be after a short shameless promotion of my companies BIRT training program. We have designed a modular training program that is focused on teaching you how BIRT works. You can take one module or all of them. The focus of our training is on how BIRT works, so that when you finish you really understand what is going on in the product.
Our training can be taken on-site, or through remote sessions of between two and four hours each. We are also happy to work with your team to customize the training to match your companies needs. If you are interested, please visit our web site and have a look.
Answers:
rowCityStateZip: { Kalamazoo }, MI USA
tablCityStateCountry: Kalamazoo, MI USA
Remember, dataSetRow syntax (as used in tablCityStateCountry) goes back to the original data. Row syntax use the table binding.