Dynamic date parameter for reports scheduling

0

Hi All,

I am recently having some problems with the jasper server scheduler. I have created a report with date as parameters it runs perfectly when I run it manually, but when I want to schedule the report I don't know how to get the dates parameters from the scheduler and feed it to the date parameters.

 

Is it possible to get the server scheduler date and use it as the date parameters for the report?

 

-ben

b_basa's picture
9
Joined: Jun 17 2009 - 5:43am
Last seen: 2 years 2 months ago

8 Answers:

2

Hi Ben,

 

I am not totally clear on whether your question is about passing dates that you would normally pass in input controls for scheduled reports or more about dynamically setting the dates that are used.  Based on the subject, I will attempt to cover the latter since the scheduling interface allows for you to provide values when you define the schedule.

 

If you wanted dynamic dates, for example "beginning of this month" to the "end of this month", I would recommend creating a parameter (and input control) that actually takes predefined strings like "start of current month", "today", etc. and then create a date parameter without an input control that has an expression that uses the string value from the first parameter with a java method, to calculate the date.  For example, the method may have a case that says if the string is "Today", then return the result of new Date();...start of month, etc. would be similar, but the date math would be a bit more complicated.

 

I hope this helps.

 

Thanks!

Matt

Jaspersoft

mgeise's picture
23037
Joined: Mar 5 2007 - 6:18am
Last seen: 2 months 2 weeks ago
1

Hi, I have a similar problem (sorry for my english, i speak spanish).

I need to dynamic set the parameter of a scheduled report to 'Yesterday', and other for 'Previous month'.

How can I do this?

Thanks

 

 

iamsuperman's picture
Joined: Apr 10 2007 - 2:12am
Last seen: 7 years 4 months ago
1

The same instructions from above would apply.  Once you have an input control and chain of parameters that allows you to enter "Yesterday" and convert it into another parameter with the equivalent calculated Date, scheduling the report with Yesterday as the input is the same as scheduling with any other input control/

Matt

Jaspersoft

mgeise's picture
23037
Joined: Mar 5 2007 - 6:18am
Last seen: 2 months 2 weeks ago
0

Hi All,

Thanks for your kind response.

I think I have already found out the solution.

 

What I did is this.

 

I scheduled the report for a certain day or certain occurence. Then I tried to get the previous dates by using org.apache.commons.lang's DateUtil.

 

You can literally pass "$P_ScheduleTime" parameter to the DateUtil's add day or date function. This will in turn give you a new date wherein you can pass as a dynamic date parameter.

 

b_basa's picture
9
Joined: Jun 17 2009 - 5:43am
Last seen: 2 years 2 months ago
0

We solved this by using SQL similar to the below, which uses a parameter like suggested above:


Hope that helps. =)

-Scott

Code:
 (CASE
WHEN $P{report_schedule} = "Month to Date" THEN (DATE(NOW()) + INTERVAL 1 DAY)
WHEN $P{report_schedule} = "Previous Month" THEN (DATE_FORMAT(CONCAT(YEAR(NOW()),"-",MONTH(NOW())-1,"-",DAY(LAST_DAY(NOW() - INTERVAL 1 MONTH))),"%Y-%m-%d") + INTERVAL 1 DAY)
WHEN $P{report_schedule} = "Previous Year" THEN (DATE_FORMAT(CONCAT(YEAR(NOW()),"-",MONTH(NOW())-1,"-",DAY(LAST_DAY(NOW() - INTERVAL 1 MONTH))),"%Y-%m-%d") + INTERVAL 1 DAY)
ELSE ($P{end_date_text} + INTERVAL 1 DAY)
END)


Post Edited by scottn at 09/21/2009 17:15
scottn's picture
6
Joined: Jan 9 2009 - 12:31pm
Last seen: 11 years 1 month ago
2

Hi,

The above works when you have JRXML templates and have access to the parameter expressions, however has anyone been able to achieve relative/dynamic dates when scheduling ad hoc reports?

I haven't been able to do this however our business really requires it.  The power of ad-hoc reporting seems to be really diminished by the fact that date input controls can't be anchored to the time of viewing/scheduling.

Any help would be greatly appreciated.  

Thanks,

Walt.

surfratwalt's picture
Joined: Dec 9 2010 - 7:41am
Last seen: 9 years 2 months ago
0

 You should be able to do this by creating a topic that has the date input controls as done here and then your users can use the topics to create adhoc reports.  Unfortunately this is not currenly available with ad hoc reports otherwise.  There are plans to add this capability in our release that is planned toward the latter half of the year.  

If you have a use case that you want to be sure is considered, my recommendation is to either describe the specific use case in a request within the tracker or to log it with Jaspersoft Support.

mgeise's picture
23037
Joined: Mar 5 2007 - 6:18am
Last seen: 2 months 2 weeks ago
0

Yeah this situation appears to be clearly lacking. Ive seen a few cases where people are clearly stating to make this work you utilize the daterange mechanism in jasper but it DOES NOT WORK. When I attempt to enter MONTH-1 in the parameter box I get an error. It's very surprising that such a rudementary feature that appears in just about every other reporting platform just simply doesnt work in this.

jbarger.consultant's picture
Joined: Dec 6 2018 - 12:00pm
Last seen: 7 months 3 days ago
Feedback
randomness