How to pass parameter dynamically from main report to drilldown report with visualize.js?

Product Version: 7.5.0

we have just started to explore visualize.js and we are stuck!!

We are rendering a simple main report which contains a pie chart and all the pie has a hyperlink, onclick of the hyperlink a drill-down report is rendered.

is there any way to pass the parameter dynamically to the drill-down report?

script used: 

 visualize({
            auth: {
                name: "superuser",
                password: "superuser",
                organization: "organizations"
            }
        }, function(v) {
            v("#main").report({
                resource: "path",
                linkOptions: {
                    beforeRender: function(linkToElemPairs) {
                        linkToElemPairs.forEach(showCursor);
                    },
                    events: {
                        "click": function(ev, link) {
                            var rpath = "";
 
                            if (link.type == "ReportExecution") {
                                $("#drill-down").html("");
                                rpath = link.parameters._report;
                                var params = link.parameters;
                                delete params['_report'];
 
                                var sampleParams = {};
                                Object.keys(params).forEach(function(key) {
                                    console.log(key);
                                    console.log(params[key]) // baz
                                    console.log();
                                    sampleParams[key] = [params[key]];
                                })
                                console.log("link  ", sampleParams);
                                v("#drill-down").report({
                                    resource: "/organizations/organization_1" + rpath,
                                     params: convertToReportParams(params)
                                });
                            }
                            console.log(link);
                        }
                    }
                },
                error: function(err) {
                    alert(err.message);
                }
            });
 
            function convertToReportParams(linkParams) {
                return _.chain(linkParams)
                    .pairs()
                    .map(function(pair) {
                        var key = pair[0],
                            val = pair[1];
                        if (!_.isArray(val)) {
                            return [key, [val]];
                        }
                        return pair;
                    })
                    .object()
                    .value();
            }
 
            function showCursor(pair) {
                var el = pair.element;
                if (typeof(el) != "undefined") {
                    el.style.cursor = "pointer";
                }
            }
        });

found the function convertToReportParams(linkParams) in the wiki https://community.jaspersoft.com/wiki/visualizejs-how-pass-report-parameters-main-report-drill-down-report-hyperlink but not able to go further as we are getting error.

Is there any way to convert link.parameters dynamically to the correct format the drill down report is expecting dynamically?

below is the details getting from the hyperlink

{
  "id": "119688132",
  "parameters": {
    "From_Date": "rO0ABXNyAA1qYXZhLnNxbC5EYXRlFPpGaD81ZpcCAAB4cgAOamF2YS51dGlsLkRhdGVoaoEBS1l0\nGQMAAHhwdwgAAAF1ijkcQHg=",
    "To_Date": "rO0ABXNyAA1qYXZhLnNxbC5EYXRlFPpGaD81ZpcCAAB4cgAOamF2YS51dGlsLkRhdGVoaoEBS1l0\nGQMAAHhwdwgAAAF2JLfkQHg=",
    "Project": "ALL",
    "Factname": "DC_06_USAG_UPTO_DALY_LIMT_INTU"
  },
  "href": "",
  "type": "ReportExecution",
  "target": "Self",
  "resource": "path"
}

bhavya.k's picture
Joined: Dec 3 2020 - 5:23am
Last seen: 2 years 3 months ago

0 Answers:

No answers yet
Feedback
randomness