Jump to content
We've recently updated our Privacy Statement, available here ×
  • Dynamic parameter generation in visualize.js links


    Scott Andersen
    • Features: JasperReports Server, Parameters Version: v8 Product: Visualize.js

     The “Report Execution” link normally displays the target report in JasperReports Server’s interactive viewer UI.  If instead you want the target to be displayed in your UI, you can use visualize.js to capture the link event coming from the Studio report and redirect it to the appropriate report.

    When implementing drill down reporting in visualize.js, you must map the parameters from the captured event link (link.parameters) to the targeted report’s parameters. These link parameters are defined when creating the hyperlink in Jaspersoft Studio. Typically the mapping of parameters is very specific between  the source-master and target-slave reports. But what if there are different links coming from the report? 

    Rather than implementing complex logic in the link event handler, another approach is to draw both the target report url and the parameters from the link and generate the parameter mapping dynamically.

    Some assumptions:

    • The parameter names in the master parameter mapping (in the Hyperlink properties) match the input parameters of the slave report.
    •  

    This example uses the following “Sample” reports provided in JasperReports Server deployment.

    • “13. Top Fives Report” – this report has links to two different reports:
      • “09. Customer Details Report” – linked to from the “Customers” list, passing the customerId.
      • “12. {Promotions Detail Report” – Linked from the “Promotions” list, passing the promotionId.

    Within the embedded-in web page javascript, do the following:

    1. Define a “createReport” function, passing in the report path and the report parameters.
      converted-image.png.29082908c96f215c737f6c328873e0af.png
    2. Define a function to format the parameter list based on the passed parameter JSON. The “link.parameters” cannot be used directly, since the visualize.js parameter  requires values be included in an array, and Studio links map content differently depending on the type of parameter passed (string vs collection). That is why a “buildParms” function is required.
      converted-image.png.686a8eb7e39d8eb72933a1a1372443ad.png
    3. Populate the <div> with the initial report.
      converted-image.png.ee65cdcb21350332652658c39530bb00.png
    4. Use the “createReport” function in the link event handler to create the target report, based on the information from the link.converted-image.png.2411c49fa3f6efbf63c5c5ea938a8e0c.png

    This example provides a simple implementation of a dynamic parameter generation in visualize.js.

    Sample drilldown web page is attached below.

     

     

    drilldownreport.html

    drilldownreport.html_0.txt


    User Feedback

    Recommended Comments

    There are no comments to display.



    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...