Problems entering Date/Time as report parameter

I am trying to build a stock movement report to list movements of specified products between specified date/times. (It is part of my Stocktake suite - you use it to show any movements between the time you ran off the stocktake data entry suite and the time you actually did the count and thus enables you to do stocktake with minimum disruption.)

Using iReports one can set the parameter type to java.sql.time or java.sql.timestamp or java.utils.Date

The latter prompts (quite reasonably) for only the date.  The other two formats work happily when you use Preview in iReports. However, when you try to run the report from Reporting|Reports you get a failure as follows:

<error-report>
<version>1.7</version>
<revision>5765</revision>
<message>Failed to get report parameters</message>
<exception>
<type>org.openvpms.report.ReportException</type>
<message>Failed to get report parameters</message>
<stackTrace>
<trace>org.openvpms.report.jasper.AbstractJasperIMReport.getParameterTypes(AbstractJasperIMReport.java:145)</trace>
<trace>org.openvpms.report.jasper.AbstractTemplatedJasperIMReport.getParameterTypes(AbstractTemplatedJasperIMReport.java:74)</trace>

Conclusion: the OPV implementation of the jasper reports parameter interface does not allow for time or timestamp parameters.

I assume that the only way to generate a date/time parameter (so that I can look for stock movements between say 1500 and 1530) is to input the time as either integers (eg 1530) or floats (eg 15.5).

Regards, Tim G

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Re: Problems entering Date/Time as report parameter

After much screwing around I have the recipe.

First set the parameters so that the parameter screen looks like:

Here the dates are dates but the times are integers.

Add a fromDateTime and a toDateTime parameter which are not prompted for, are set as type java.sql.Timestamp and set their default Value Expression to:

 new java.sql.Timestamp($P{fromDate}.getYear(),$P{fromDate}.getMonth(),$P{fromDate}.getDate(),$P{fromTime}/100,$P{fromTime}%100,0,0) 

Now in the SQL you can do:

 where (p.activity_start_time >= $P{fromDateTime}
     and p.activity_start_time <= $P{toDateTime}) 

Note that if you use java.util.Date as the parameter class rather than java.sql.Timestamp then the time part of the date will be ignored.

And the output is:

Recommendation: don't worry about supporting time and timstamp fields as input parameters.  The recipe for handing a date/time is given above.

Regards, Tim G

Re: Problems entering Date/Time as report parameter

The error is actually coming from JasperReports, but you'll need revision 5787 to see the cause. Your approach is fine however. There's no straight forward way of inputting date/times.

-Tim A

Syndicate content