Difference between revisions of "BIRT/FAQ/Scripting"
Revision as of 11:40, 10 July 2006
Back to BIRT FAQ Index
- 1 Aggregates (Totals)
- 2 Scripting
- 3 Accessing Java Classes
Q: What aggregate operations does BIRT support?
"Aggregate" is the fancy word to describe totals. BIRT supports a wide variety of totals: sum, running sum, average, minimum, maximum, count, count distinct, and many more. See the ROM Scripting Specification for details.
Q: Is it possible to use cell.setProperty( ) to set the width of cells?
Answered by Stanley Wang You can not set column width dynamically for now. Runtime scripting is limited to property access and data-manipulations for this release. More will come in BIRT 2.0.
Q: Does BIRT support look-ahead (two-pass) aggregates?
Look-ahead aggregates are of the form "this value as a percentage of an overall total". For example, a customer's sales as a percentage of overall sales for a sales rep, sales region, and so on. These are often called two-pass aggregates becuase they require the reporting tool to make one pass over the data to compute totals, then another pass to compute the percentages for each record.
BIRT does provide support for such totals. Just enter the calculation and BIRT figures out the right way to compute it:
Total.percent( row.Sales, Total.sum( row.Sales ) )
Q: Is an example of simple calculations like count, sum, max, min?
Q: Does BIRT support page totals?
Some reports may want to display totals over data displayed on a page of the report. For example, a count of employees on that page, and sum of their salaries.
BIRT release 1.0 delivers reports as a single web page, so the question is moot for this release. BIRT reports are paginated when printed as PDF, but BIRT uses Apache FOP to do the formatting, and so BIRT does not have visiblity into the pagination.
That said, if there is sufficient interest, the BIRT team will consider page totals for a future release.
Q: Can I add custom logic (scripting) to my report?
sum( row.orderTotal )
This summarizes the orderTotal column over all rows. This makes aggregates look like other expressions, even though the BIRT report engine needs to "rewrite" them.
Q: Good, but most report developers don't like to write code.
1. Simple expressions: row.Price * row.Quantity 2. Business expressions: choose a salutation (Mr., Mrs., Ms., etc.) depending on a database code, and concatenate the salutation, first name and last name. 3. Complex logic written in Java: Compute the recommendation rating for a stock based on factors in the database, and proprietary stock-rating algorithms.
Simple tasks require no code. This includes conditional formatting (make negative numbers red, for example), data transformations (filters, sorting, totals), conditional display (hide certain fields for certain types of customers), and so on.
Accessing Java Classes
Q: Can BIRT access existing Java code or objects?
importPackage( "com.company.AppLogic" );
importPackage is not suported in BIRT 1.0, so the previous line will not work: To use outside packages, you will need to use the fully qualified name of the object var abc;
abc = new Packages.com.company.AppLogic();
obj = new MyClass( ); result = obj.calculate( row.balance, row.dueDate );