Search code examples
iccubeiccube-reporting

Displaying a report with JS: How to check if a report exist?


Is there a convenient was to check if a report with the given report name exists using JavaScript?

Following this official guide on how to display a report I managed to display a report with the name given in the URL. If the given report name does not match a report I get a error:

Could not open successfully the report 'fake-name' (The report '/shared/fake-name.icc-report (null)' does not exists.)

So I want to redirect the user if the report does not exists and for that I need something like a function that gives me true or false based on the report name.

Is there any way this can be done?

Thanks. :)


Solution

  • I suggest using these options to have access to openReport callback:

    var options = {
    
            root: ic3root,
            rootLocal: ic3rootLocal,
            imagesPath: 'images',
    
            //librariesMode:'dev',
    
            callback: function () {
    
                $('#intro').remove();
    
                var ic3reporting = new ic3.Reporting(
                        {
                            noticesLevel: ic3.NoticeLevel.ERROR,
    
                            dsSettings: {
                                url: "http://<your_domain>/icCube/gvi"
                            }
                        });
    
                ic3reporting.setupGVIConfiguration(function () {
                    ic3reporting.setupApplication(
                            {
                                mode: ic3.MainReportMode.REPORTING,
                                hideTopPanel: true,
                                noticesLevel: ic3.NoticeLevel.ERROR,
                                container: $("#container")
                            });
    
                    ic3reporting.openReport({
                        report: {
                            name: 'shared/report23'
                        }
                    }, function (reportState) {
                        var reportExists = _.isEmpty(ic3reporting.reportName());
                    })
    
                });
            }
        };
    
        ic3ready(options);
    

    You may want to redirect user in case "reportExists" equals to false