passing a date parameter into a sub report not working - any ideas?

I have a subreport which I want to re-use 5 times on the main report, just passing in different date ranges (today, yesterday, lst month etc).

The sub report takes 2 java.util.date parameters.  If I run the sub report on its own, either using the prompt for option and chosing dates, or entering TODAY( ) in the "Default Vlue Expression", the sub report shows the correct values.

Now if I call the sub reports from the main report, passing to them the same expression (e.g. TODAY( )), I get all zeros back in all the sub reports.

In the Mail report I have this:

<detail>
<band height="340" splitType="Stretch">
<subreport runToBottom="true">
<reportElement x="80" y="0" width="80" height="200" uuid="7cd92266-e1d4-4394-a58a-67430889f229"/>
<subreportParameter name="P_FROM">
<subreportParameterExpression><![CDATA[TODAY( )]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="P_TO">
<subreportParameterExpression><![CDATA[TODAY( )]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA["dashboard/dash-slice.jasper"]]></subreportExpression>
</subreport>
<subreport>
<reportElement x="160" y="0" width="80" height="200" uuid="de0997be-7f4d-4ee7-8b70-8636fe152b05"/>
<subreportParameter name="P_FROM">
<subreportParameterExpression><![CDATA[EDATE(NOW( ),-1)]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="P_TO">
<subreportParameterExpression><![CDATA[new Date()]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA["dashboard/dash-slice.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
 
This should pass the parametes into the sub report. but I notice there is no way to define the type of the parameters going in - are they converted to strings or simlar?   Is this the problem perhaps?
 
In the sub report, the parameters are defined like this:
 
<parameter name="P_FROM" class="java.util.Date">
<parameterDescription><![CDATA[]]></parameterDescription>
<defaultValueExpression><![CDATA[TODAY( )]]></defaultValueExpression>
</parameter>
<parameter name="P_TO" class="java.util.Date">
<parameterDescription><![CDATA[]]></parameterDescription>
<defaultValueExpression><![CDATA[TODAY( )]]></defaultValueExpression>
</parameter>
 
In the SQL, I have something like this:
 
<queryString language="SQL">
<![CDATA[select * from
(select count(p.id) as registrations
from players p
where date(p.creationTime) BETWEEN $P{P_FROM} AND $P{P_TO}

 

john.v.little's picture
Joined: Aug 28 2014 - 3:29am
Last seen: 8 years 6 months ago

1 Answer:

I found the problem.

It seems you have to compile the sub report every time before you want to preview the main report.  It just uses an old version without warning.

john.v.little's picture
Joined: Aug 28 2014 - 3:29am
Last seen: 8 years 6 months ago
Feedback
randomness