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

Sending parameters from Visualize.js to Query on JasperReport Server


antonuccijulian

Recommended Posts

Hi u all. 

I am new on using JasperReports Server. I found "Visualize.js" in order to connect my web app with the server but I got the next problem. 

I wanted to send some parameters from my web app (using Visualize.js) to a query, which helps me to fill the report with data from a table on my database. I tried like this... 

/* ------------------------------------------------------------------------------------------ CODE BELOW ------------------------------------------------------------------------------------------ */

visualize({
    auth: {
        name: "jasperadmin",
        password: "jasperadmin",
        organization:"organization_1",
        timezone: "Europe/Helsinki"
    }
}, function (v) { 
    $(':disabled').prop('disabled', false);

    $("#selected_resource").change(function () {
        //add custom export format
        //(should throw a proper error)
        var reportExports =  v.report.exportFormats.concat(["json"]);

        report = v.report({
            resource: $("#selected_resource").val(),
            container: "#container",
            params: {
                nombre:["Julian"]
            },
            success: function () {
                console.log(report.params());
            },
            
            error: function (error) {
                console.log(error);
            }
        });

    });

    $("#exportButton").click(function () {        
        report.export({
            //export options here        
            outputFormat: $("#exportTo").val(),
            //exports all pages if not specified
            //pages: "1-2"
        }, function (link) {
           var url = link.href ? link.href : link;
           window.location.href = url;
        }, function (error) {
            console.log(error);
        });
    });


    function createReport(uri) {        
        v("#container")
            .report({
                resource: uri,
                container: "#container",
                params: {
                    nombre:["Julian"]
                },
                error: function (err) {
                    alert(err.message);
                }
            });
    };

}, function () {
    alert("Unexpected error!");
});
/* ------------------------------------------------------------------------------------------ END OF CODE ------------------------------------------------------------------------------------------ */

And respecting to JasperResports server, I have tried to fill my report with a query without parameters and It worked all right. 

select * from "TestTable"

But when I try to add some parameters to filter the query It crash

select * from "TestTable" where nombre = $P{nombre}

and the log tell me something like this....

/* ------------------------------------------------------------------------------------ ERROR BELOW ------------------------------------------------------------------------------------ */

2018-07-06 12:34:57,327 ERROR GenericExceptionMapper,http-nio-8081-exec-6:51 - Unexpected error occurs
net.sf.jasperreports.engine.JRRuntimeException: Parameter "nombre" does not exist.
    at net.sf.jasperreports.engine.query.JRAbstractQueryExecuter.checkParameter(JRAbstractQueryExecuter.java:847)
    at net.sf.jasperreports.engine.query.JRAbstractQueryExecuter.appendParameterChunk(JRAbstractQueryExecuter.java:406)
    at net.sf.jasperreports.engine.query.JRAbstractQueryExecuter.appendQueryChunk(JRAbstractQueryExecuter.java:379)
    at net.sf.jasperreports.engine.query.JRAbstractQueryExecuter.parseQuery(JRAbstractQueryExecuter.java:359)
    at net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.<init>(JRJdbcQueryExecuter.java:176)
    at com.jaspersoft.jasperserver.api.engine.jasperreports.util.JRTimezoneJdbcQueryExecuter.<init>(JRTimezoneJdbcQueryExecuter.java:125)
    at com.jaspersoft.commons.util.JSControlledJdbcQueryExecuter.<init>(JSControlledJdbcQueryExecuter.java:63)
    at com.jaspersoft.commons.util.JSControlledJdbcQueryExecuterFactory.createQueryExecuter(JSControlledJdbcQueryExecuterFactory.java:24)
    at net.sf.jasperreports.engine.query.AbstractQueryExecuterFactory.createQueryExecuter(AbstractQueryExecuterFactory.java:49)
    at com.jaspersoft.jasperserver.api.engine.jasperreports.util.JRQueryExecuterAdapter.executeQuery(JRQueryExecuterAdapter.java:131)
    at com.jaspersoft.jasperserver.api.engine.jasperreports.util.JRQueryExecuterAdapter.executeQuery(JRQueryExecuterAdapter.java:108)
    at com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl.executeQuery(EngineServiceImpl.java:2348)
    at sun.reflect.GeneratedMethodAccessor1694.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)

/* ------------------------------------------------------------------------------------ END OF ERROR ------------------------------------------------------------------------------------ */

I tried adding some Input Control but I really don't know how is the right way to do that. 

If someone can help me I would be very grateful.
Thank you in advance. Shulian

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

When you deploy the report to jasper server you need to create or link the input control to the given report in jasperserver. 
Either you create the input control or if you have alreadt created it on the jasper server just browes the repository and select the alreadt created input control. 
The input control type is also imported. 
I would suggest to deploy the report on jasperserver, assign input control and then run the report as a user in jasper server and check if you can select and change the input control and ensure the report updates based on selections. 
Then you know your query and parameter combination on jrxml level is correct. 

https://community.jaspersoft.com/documentation/jasperreports-server-user-guide/adding-input-controls

You know that the report deployment to jasperserver is correct. 
Then it just leaves your visualise.js implementation to check. 
 

Link to comment
Share on other sites

  • 6 months later...

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