I have a way to make the dateTime parameter in my report set to today by default. This was a little scarce information so now I like to share it.<br />
<br />
The problem: I need to start my report with today as the default parameter. <br />
i.e. params["latestDate"] = today;<br />
<br />
The report will allow surfing back and forward in time with links that send the selected date as the same parameter.<br />
something like: <br />
linkDate = params["latestDate"] - 7days;<br />
hyperlink?latestDate=linkdate<br />
(this is just the idea. I used dates gathered by sql for this as a data table)<br />
<br />
The date runs in a query which gathers data from one year ago.<br />
i.e. SELECT * FROM table WHERE date <= ?<br />
the ? is referenced in the query builder to the report parameter. <br />
<br />
lastly, the date must be displayed in the report in a dynamic text box.<br />
i.e. <value-of>params["latestDate"]</value-of><br />
<br />
The answer that worked for me is here!<br />
1. Create a report parameter in the data section with type dateTime.<br />
2. Prepare the query in the data section with a ? in the place of the date.<br />
3. Link the question mark to the date parameter from the query builder.<br />
4. In the report outline view, click on the title.<br />
5. In the design window, click on scripts.<br />
6. Use a script like the one below in the 'initialize' section.<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
importPackage(Packages.java.util);
if (params["latestDate"].value == null)
{
globalToday = new Date();
reportContext.setParameterValue("latestDate", globalToday);
} else {
globalToday = reportContext.getParameterValue("latestDate");
}
</pre>
<br />
Now the report will use today's date for the parameter in the query if one is not sent in. But if you send it a date, (from a link in my case) it will use the value that you send it.<br />
<br />
Notes: <br />
The importPackage line makes it work. I found that in a tutorial located here:<br />
<a class='bbc_url' href='
http://davidjberman.com/blogs/birt_reporting/default.aspx'>BIRT Java Reporting</a><br />
<br />
7. To display the date in the report make a dynamic text box that says something like this:<br />
<br />
Report shows data up until <VALUE-OF>globalToday</VALUE-OF>.<br />
<br />
8. I hope this can help someone with the same situation I was in.<br />
<br />
I don't really know how this works under the hood, (BIRT Noob & Java super-noob) but I spent a long time trying to make it happen. If you can offer any clear explanation or improvements please do, and maybe notify me.