1
votes

I have several reports that use weekly Start date and End date parameters. The goal is to have these reports scheduled and emailed to clients on weekly basis whilst allowing them to login and select their own dates when necessary. On the report side I have startdate and enddate java.util date parameters with default value expressions and on the server side there are 2 date type input parameters with exact name.

Default dates are calculated by Groovy scripts. Date calculations work perfectly fine; when you login to Jasperserver and open the report, they are always correct and reports run fine manually.

However the reports scheduler gets stuck. I set the scheduler to start on a specific date (next Monday 00:05) and set the recurrence as Calendar type to repeat evert month, every Monday at 00:05. The problem is that although the scheduler works, it will ONLY use the current date parameters and will not refresh them on the second run. For example if I set the scheduler now, next Monday I will have the reports sent to my email with date inputs startdate: 3-11-14, enddate: 10-11-14. This is correct for the first run. However, all the upcoming weeks, it will use these specific parameters and will not refresh the dates.

I believe what I am looking for is VERY simple. I have my report calculate everything correctly and all I need from Jasperserver is to run it every Monday WITHOUT storing the input parameters. If it ONLY runs it, on scheduled time, all would be great but somehow scheduler stores the parameter values which are correct only at the date the scheduler is set!

I have been working on this for ages and am really annoyed I can't find a permanent, reliable solution. Any help would be greatly appreciated.

1
I'm in the same boat. It's seems like a really simple scenario that the developers should have seen when writing the scheduler system. Writing a Java class to interpret "This Month" seems ridiculous.Joel

1 Answers

0
votes

This may already be a new feature in later versions of JasperReports Server, but I know this will work in 4.5 and above (and probably will work for older versions as well). You will have to create a JAVA class that takes in a "string" which you will have to pre-populate with things like "This Month" and "Last 10 days". Based on the String passed in, it will return the correct dates. You can create a drop down parameter with these pre-populated strings. A method in that class will have to be written for each of your input dates. Here is some sample JRXML of how this would mockup:

<parameter name="DateInputControl" class="java.lang.String">
    <defaultValueExpression><![CDATA["This Month"]]></defaultValueExpression>
</parameter>
<parameter name="QueryBeginDate" class="java.util.Date" isForPrompting="false">
    <defaultValueExpression> 
        <![CDATA[com.your.package.YourClass.getBeginDate($P{DateInputControl})]]>
    </defaultValueExpression>
</parameter>
<parameter name="QueryEndDate" class="java.util.Date" isForPrompting="false">
    <defaultValueExpression>   
        <![CDATA[com.your.package.YourClass.getEndDate($P{DateInputControl})]]> 
    </defaultValueExpression>
</parameter>

Obviously there is a little more work to it than this, but hopefully this will get you down the path. I highly recommend using JODA time in your custom JAVA class.

With this setup, you can schedule using the required presets like "Last 10 Days" and your scheduled report will run using the rolling dates. The dates for your report will now always be relative (or dynamic) based on the current date.