anandharaj Posted January 4, 2007 Share Posted January 4, 2007 Hi.. I created a report which have an input value (date) and extract data based on that value. When i schedule the job, i need to specify the input value (parameter). How do i set so that the value is current date or current date - n days. This is for report which run on daily basis. Please help on this matter. Link to comment Share on other sites More sharing options...
lucianc Posted January 4, 2007 Share Posted January 4, 2007 If you define a report parameter named _ScheduledTime of type java.util.Date, the report scheduler will set as parameter value the job scheduled execution date/time. You can then create another parameter, set its default value as $P{_ScheduledTime} - n days and use this parameter in your query. HTH,Lucian Link to comment Share on other sites More sharing options...
anandharaj Posted January 4, 2007 Author Share Posted January 4, 2007 Thanks for reply Can you give further explanation on how to do this (the code). The $P{_ScheduledTime} is predefine JI parameter? Link to comment Share on other sites More sharing options...
anandharaj Posted January 4, 2007 Author Share Posted January 4, 2007 Are you meaning something like this? <parameter name="_ScheduledTime" isForPrompting="false" class="java.util.Date"/><parameter name="myDate" isForPrompting="true" class="java.util.Date"> <defaultValueExpression ><![CDATA[$P{_ScheduledTime} - ]></defaultValueExpression> </parameter> Post edited by: anandharaj, at: 2007/01/04 14:53 Link to comment Share on other sites More sharing options...
lucianc Posted January 8, 2007 Share Posted January 8, 2007 JR report expressions are Java expressions, unless you use a non-Java based report compiler, such as Groovy. In Java, you cannot do date - 1 to subtract a number of days from a date. If you want to do something like that, you would need to take a look at java.util.Calendar or use an utility class such as DateUtils from Commons Lang. HTH,Lucian Link to comment Share on other sites More sharing options...
anandharaj Posted January 9, 2007 Author Share Posted January 9, 2007 Thanks lucianc, I found this code in Inet. Code:Calendar cal = new GregorianCalendar();cal.add(Calendar.DATE, -1);java.util.Date date = cal.getTime(); How to use this code in JR. Meaning parse to a parameter? Can anyone help me on this matter. Im stack on this matter. Urgent... I'll appreciate if you guys can give with example code (jrxml)Post edited by: anandharaj, at: 2007/01/09 05:34 Link to comment Share on other sites More sharing options...
lucianc Posted January 9, 2007 Share Posted January 9, 2007 You can't put this code directly in the JRXML, you need to put it for instance in a static method of a class, then make sure that the compiled class is included in your application's classpath and call the method in the JRXML:Code:package my.package;public class MyDateUtils { public static Date yesterday() { Calendar cal = new GregorianCalendar(); cal.add(Calendar.DATE, -1); return cal.getTime(); }}-----<parameter name="yesterday" class="java.util.Date" isForPrompting="false"> <defaultValueExpression>my.package.MyDateUtils.yesterday()</defaultValueExpression></parameter> Or you can use Commons Lang and do (you would obviously need the Commons Lang jar on your classpath)Code:[code]<parameter name="yesterday" class="java.util.Date" isForPrompting="false"> <defaultValueExpression>org.apache.commons.lang.time.DateUtils.addDays(new Date(), -1)</defaultValueExpression></parameter> HTH,Lucian Link to comment Share on other sites More sharing options...
anandharaj Posted January 9, 2007 Author Share Posted January 9, 2007 Thank you very much lucianc. I'll try it. Link to comment Share on other sites More sharing options...
anandharaj Posted January 14, 2007 Author Share Posted January 14, 2007 Hi Lucianc I try the sample that you gave me...Its works fine. Thank you very much. Link to comment Share on other sites More sharing options...
jrechter Posted July 8, 2009 Share Posted July 8, 2009 After searching on how to set a daily scheduled task on a report whose date field has to default to yesterday (current day - 1), I came upon this thread, which seemingly would fix my problem, but alas, did not.When I manually run the report, I can default the End Date to the previous day, and the report runs fine, giving me the previous day's information.When I scheduled this report to run each day, I would expect the End Date to increment a day at a time, but instead, it saves the initial date that the schedule was made, and the result is that I get the same report every day. End Date is always 07/04/2009. I've played around with _ScheduledTime but have been unsuccessful.Any help would be appreciated on how to make the date parameters dynamic within scheduled tasks.Thanks. Link to comment Share on other sites More sharing options...
cmeier Posted July 9, 2009 Share Posted July 9, 2009 Try something like this for the parameter. The code below sets the date to the current date + 1 yearCode: <parameter name="vend_order_date_1_2" class="java.util.Date" isForPrompting="false"> <defaultValueExpression><![CDATA[new java.util.GregorianCalendar(new java.util.GregorianCalendar().get(Calendar.YEAR) + 1,new java.util.GregorianCalendar().get(Calendar.MONTH),new java.util.GregorianCalendar().get(Calendar.DAY_OF_MONTH)).getTime()]]></defaultValueExpression> </parameter> Link to comment Share on other sites More sharing options...
scottn Posted September 21, 2009 Share Posted September 21, 2009 jrechterWrote: After searching on how to set a daily scheduled task on a report whose date field has to default to yesterday (current day - 1), I came upon this thread, which seemingly would fix my problem, but alas, did not. When I manually run the report, I can default the End Date to the previous day, and the report runs fine, giving me the previous day's information. When I scheduled this report to run each day, I would expect the End Date to increment a day at a time, but instead, it saves the initial date that the schedule was made, and the result is that I get the same report every day. End Date is always 07/04/2009. I've played around with _ScheduledTime but have been unsuccessful. Any help would be appreciated on how to make the date parameters dynamic within scheduled tasks. Thanks. Hi,We solved this by adding some SQL to the report query to give us different scheduling options, and then you simply pass the parameter to the report for it to run (i.e. "Previous Day" or "Month to Date"). Below is the SQL as an example.-ScottCode: (CASEWHEN $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) Link to comment Share on other sites More sharing options...
federico.cattozzi Posted February 4, 2011 Share Posted February 4, 2011 "_ScheduledTime" doesn't work for me!I have:1. defined a new parameter<parameter name="_ScheduledTime" class="java.util.Date"/>2. created a new Input Control named "_ScheduledTime"3. scheduled new job for the reportI try to print $P{_ScheduledTime} on the report, but it is "null".Why? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now