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

  • sameernori

    [toc on_off::hide=1]

    You will often want to prompt users to restrict the data they retrieve based on a date range. This article assumes you design the report in iReport Designer and publish it to JasperReports Server for shared use.

    In iReport

    1. Create two parameters in your report.

      Name: start_date
      Parameter class: java.util.Date
      Use as prompt: checked
      Default Value Expression: leave blank/null

      Name: end_date
      Parameter class: java.util.Date
      Use as prompt: checked
      Default Value Expression: leave blank/null or you can use new java.util.Date() to populate the parameter with the current date

      DateBetween_p2.png.bf4e5bdea9aba97bb94c695f5b004f2f.png

    2. Add this to your query:

      WHERE <your_table.column> BETWEEN $P{start_date} AND $P{end_date}</your_table.column>

    3. Save and then test by clicking Preview in iReport.

    Assuming it runs well, you can load the file to JasperReports Server. You can stay within iReport Designer to do this.

    1. Open the Repository Navigator and navigate to a folder where you want to save the report.
    2. Right-click the folder and click Add > Report Unit.
    3. Enter the name, label etc. and click Next.
    4. Click the Get source from current opened report button and click Next.
    5. Locate the Data Source from the repository (e.g., Dev01) and click Finish.

    When prompted if you want to open the file from the server, click yes.

    In JasperReports Server

    Here you will add the Input Controls that map run-time values (generally user input) to the report parameters. There are several ways to add input controls. This is just one of them.

    Switch to JasperReports Server and login as an administrator (jasperadmin or superuser, for example).

    1. Right-click the report in the Repository browser. Select Edit, then click Controls & Resources on the left sidebar.
    2. Click the Add Control button.
    3. Unless you already have the input control defined, click Locally Defined.
    4. Enter the following for Input Control Details and when done click Next.
      • Parameter Name: start_date [Note: it is important that the parameter name exactly matches the parameter defined in the report definition]
      • Prompt Text: Enter a start date
      • Type: Single Value
      • Mandatory: (optional)
      • Read Only: (optional)
      • Visible: checked
    5. Locate Datatype: Click From the Repository and select one of the sample date types that Jaspersoft includes, e.g., /organizations/organization_1/datatypes/date. Click Next.
    6. Repeat steps 2-4, but enter end_date for the Input Control name.
    7. Click the Always prompt checkbox. You can display the Controls layout on the "Top of page" if you like. Click Finish, then Save.

    Test the report

    Your report should run with a calendar input control, as shown below.
    DateBetween.png.75efa9b67fa581efc2504599b7e3d420.png
     

    DateBetween.png.d926a169f23c771b481234c15f40ff8a.png


    User Feedback

    Recommended Comments



    Guest
    This is now closed for further comments

×
×
  • Create New...