Jump to content
We've recently updated our Privacy Statement, available here ×

Getting it to prompt me for a date range


viking79

Recommended Posts

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

The only way to do that is to use some sort of front end to allow the user to select this. If you are using JasperServer I beleive it allows you to create controls to do this. If you use your own front end you will need to create a GUI that collects your values them kicks off the report.

Link to comment
Share on other sites

Svenn is correct--it's really a two-part question.  The iReport of the answer is that you need to create parameters for the values you plan to input and use those parameters in your query...e.g.:

SELECT po.id, po,description, po.datecreated FROM purchase_order as po WHERE po.date_created BETWEEN $P{StartDate} AND $P{EndDate}

While testing in the preview mode of iReport, this is in fact enough to make it prompt you for the two dates.

The second part of the answer depends on how your end user runs the report.  Are you using JasperReports Server or do you have a Java program that is running your report just using JasperReport Library, or...?

If your end user is using JasperReports Server, then you need to:

1. Deploy your report to the repository in JasperServer

2. Add input controls for each parameter that you want to prompt for

3. Change the property of the report so that it always prompts (this isn't actually necessary--you could have the report automatically run once with the default values and then rely on the user to click on the oh-so-subtle (at least in Version 3.7) "Report options" icon to enter new values.  But in most cases, I find it's better to always prompt first.

Each of these three steps is relatively easy if you have the repository navigator plug-in and are used to finding your way around the repository.  I've even defined standard input controls called StartDate and EndDate in the public folder of the repository so I can just link to them instead of creating new, local input controls each time.  If you have problems with the input controls, you'll probably want to post on the JasperReports Server forum rather than iReport.

If your end user is running some application you've written that in turn runs the report through JasperReports Library, then you will of course have to do your own prompting.  How you pass that value along to the report depends on what you're doing, but if it's a Java application, you probably use:

HashMap jasperParameter = new HashMap();

jasperParameter.put("StartDate", startDate);

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, jasperParameter, connection);

You can then also use the various exoprters to create PDF, etc.  If you have questions about THAT process, you'll probably want to post on the JasperReports Library forum.

Carl

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...