One of the most commonly asked questions over the past few years in the newsgroups have been "How can I set a date parameter to default to the current date?"
Before BIRT 2.5, this was not an easy task to accomplish. However, new to BIRT 2.5 is the ability to set a date parameter's default value via script. Let's go about it:
defaultParameterValueReport.rptdesign
. dsOrderRange
, with the help of following query:select * from CLASSICMODELS.ORDERS where CLASSICMODELS.ORDERS.ORDERDATE between ? and ?
prmStartDate
and prmEndDate
. Make sure the two dateset parameters and two report parameters are of type Date
. prmStartDate
. In the drop-down box next to Default value, select Javascript Syntax and continue.//bring in the java.util package into the scripting scope importPackage( java.util ); //create a new GregorianCalendar object var cal = new java.util.GregorianCalendar(); //set the date to now cal.setTime(new Date()); //substract 20 days cal.add(Calendar.DAY_OF_MONTH, -20); //return the start date cal.getTime();
prmEndDate
and set the expression to the following:new Date();
prmStartDate
to Column 2. prmEndDate
to Column 3.Initially, we won't see any date in the report. This is because the data in the Classic Cars Database is from 2005, so there is no date in range. But we can see from the Orders Between header that the date range has start date set to 20 days before the current date whereas the end date is the current date. We can change these at run time.