Export PDF of Report by button click on Dashboard

I have a dashboard that has multiple layers a user can navigate through. I also have a report that provides the same information as the dashboard but in a multi-paged view. Now I want to add a button to the dashboard so that when the user clicks on it, it exports the report to PDF applying the filters that the user has selected on the dashboard.

I started of with the script here: https://www.dundas.com/support/developer/script-library/Export/Create-an-Export-for-a-Report

The difference is that I do not want the report to be embedded on my dashboard for performance reasons. The script in the example has the option to add the view that needs to be imported:
image
My problem is that I do not know how to reference a non embedded view here and also pass my filters into the report before it is exported.

Has anyone achieved what I am trying to do?

Hi Marina,

You can achieve that by using the “getReportById” method from reportService. It will return the object of the report that will contain all the viewParameters of that report, then you can loop through these ViewParameters and find the one with matching id and then change its value.

After that you need to pass this updated object to ExportService and then redirect page to a new URL.

Let me know if it helps or if you have more questions.

1 Like

Hey Dinara,
thank you. That was was the missing piece. I got it to work now. In case others have similar uses cases here is my final script. It exports a non embedded report and also allows to pass view parameter values from dashboard to report before the export.

var reportService = this.getService('ReportService');
var reportPromise = reportService.getReportById('<your report id here>');

// Create paper Settings from size.
// https://www.dundas.com/support/api-docs/js/#API%20Reference/dundas/print/PaperSettings/Methods/fromPaperSize.html
var paperSettings = dundas.print.PaperSettings.fromPaperSize(dundas.print.PaperSize.A4);
paperSettings.marginBottom = 0;
paperSettings.marginTop = 0;
paperSettings.marginLeft = 0;
paperSettings.marginRight = 0;
  
// Set the PaperSettings orientation property,
// https://www.dundas.com/support/api-docs/js/#API%20Reference/dundas/print/PaperSettings/Properties/orientation.html
paperSettings.orientation = dundas.print.PaperOrientation.LANDSCAPE;

//get the dashboard view parameters (I wanted to pass a language to my report)
var parentView = this.parentView;
var languageParamD =  parentView.control.getViewParameterByName("LanguageParam");


reportPromise.done(function(report){
//get the report view parameters
var languageParamR = report.viewParameters.filter(function(item){return item.name == 
'LanguageParam'})[0];
  
//set to new values
languageParamR.parameterValue = languageParamD.parameterValue;
  

// Create the PDF Options
// https://www.dundas.com/support/api-docs/js/#API%20Reference/dundas/export/ExportHelper/Methods/exportPDF.html
var pdfOptions =
   {
    appendDateToFileName: true,
    overrideFileName: false,
    openOnCompletion: true,
    enableOverlay: true,
    paperSettings: paperSettings,
    view: report
  };

// Export the PDF with the PDF options.
// https://www.dundas.com/support/api-docs/js/#API%20Reference/dundas/export/ExportHelper/Methods/exportPDF.html
dundas.export.ExportHelper.exportPDF(pdfOptions);
});
3 Likes

Awesome, I’m glad it worked!