Pergunta

Let me preface by saying that I am a noob to JasperReports, so I apologize if there is an obvious answer to my question. I have an existing JR report that runs manually on one month intervals. I can open the report up, select an input month from the dropdown, and it will feed me back data for that month.

In addition to manual monthly runs, I want this report to to run on a weekly schedule and return data for the past 7 days only.

I see that I can set up a scheduled run pretty easily, but to me it looks like the input is fixed, and I will only get the same week back, week after week.

I am using iReport 4.5.

I feel like the easiest solution will be to duplicate this report, and make the new report run weekly functions only (I'll never do a manual run for weekly, only monthly). But after going through some of the tutorials online, I don't see how to make a report run for the previous seven days only.

Foi útil?

Solução

Create two parameters called start_date and end_date, of type Date. Then, in your query, use the following syntax (I have an Oracle data source; adjust for your own needs):

WHERE TRUNC(the_date) BETWEEN COALESCE($P{start_date}, TRUNC(sysdate-7)) 
                      AND COALESCE($P{end_date}, TRUNC(sysdate))

If the user is running the report manually, he or she can input a start and end date through your input controls. If the report is a scheduled report, leave the input controls empty and it will default to the last 7 days.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top