Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
How to set default value of parameter in report equal to CurrentDate - 30 days
IvanB
Hi guys,
I saw few examples where people showed how to write scripts in Data Set to handle the issue in this topic. But if I need to use Actuate Information Object Data Source for Data Set, I don't see a possibility to use Scripted Data Source and Actuate Information Object Data Source together.
So what we need is that one Datetime parameter would have CURRENT_DATE value by default, another Datetime parameter would have (CURRENT_DATE - 1 month) by default. Then while loading report our Data Set based on Actuate Information Object Data Source will filter query data accordingly since parameters in Information object are linked to report parameters.
Thanks!
Find more posts tagged with
Comments
bhanley
This recent post is doing something similar:<br />
<br />
<a class='bbc_url' href='
http://www.birt-exchange.org/forum/designing-birt-reports/18820-how-i-set-value-static-parameter-depend-todays-date.html'>http://www.birt-exchange.org/forum/designing-birt-reports/18820-how-i-set-value-static-parameter-depend-todays-date.html</a><br
/>
<br />
It the scripting layer (the Initialize event for example) create two global variables. Set one to the current date, and then another to the current date minus 30 days (see the post referenced above). Then you can use those variable in the query by binding them to parameters on the data set.<br />
<br />
Good Luck!
IvanB
<blockquote class='ipsBlockquote' data-author="bhanley"><p>This recent post is doing something similar:<br />
<br />
<a class='bbc_url' href='
http://www.birt-exchange.org/forum/designing-birt-reports/18820-how-i-set-value-static-parameter-depend-todays-date.html'>http://www.birt-exchange.org/forum/designing-birt-reports/18820-how-i-set-value-static-parameter-depend-todays-date.html</a><br
/>
<br />
It the scripting layer (the Initialize event for example) create two global variables. Set one to the current date, and then another to the current date minus 30 days (see the post referenced above). Then you can use those variable in the query by binding them to parameters on the data set.<br />
<br />
Good Luck!</p></blockquote>
<br />
Thank you for response.<br />
When I create Data Set using Information Object there are 5 possible methods: beforeOpen, beforeClose, onFetch, afterOpen, afterClose.<br />
It seams that beforeOpen fits the best. But I can't figure out how to set parameter. Let it be just String. How is it possible to set parameter value in Script?
IvanB
I got the solution. When you just open report, you can switch to Script tab and there put the code in initialize method:
calendarTo = Packages.java.util.Calendar.getInstance();
calendarFrom = Packages.java.util.Calendar.getInstance();
calendarFrom.add(Packages.java.util.Calendar.MONTH, -1);
if(params["DateFrom"].value == null){
params["DateFrom"] = calendarFrom.getTime();
}
if(params["DateTo"].value == null){
params["DateTo"] = calendarTo.getTime();
}
Then you should take two parameters: DateFrom and DateTo and link them to Data Set parameters.
Suppose you have a query: select inv.invoice_id, inv.invoice_amount, inv.invoice_date from INVOICE inv where ? < inv.invoice_date and inv.invoice_date < ?
Then if user doesn't set values for report parameters then you have query for your default values, namely Current_Date and Current_Date - 1 month.
If user sets values for parameter then you will get result for those parameter values.
Hope this will help to someone.
It would be nice to have calendar for parameters of Datetime type to set your values before loading the report, but I don't see how it could be done.