Exporting Report with date parameter

Dear community,

little background
I have a main dashboard for my clients, the dashboard has a date filter, I have a report connected to the dashboard and presenting the data in a way it’s possible to print them in a feasible way.

I’m transferring the date parameter from the main dashboard via the navigate option to the report.

on both, I have a date parameter - the 2 of them connected, only the dashboard is affecting the date on the report.

I didn’t give permission to the users to be able to share the report via the GUI of Dundas, so the clients can print the report via clicking on print image, the click is a script i took from this link - https://www.dundas.com/support/developer/script-library/Export/Create-an-Export-for-a-Report

The Issue
when downloading the pdf, the data items are filtered by the date parameter are showing only the default data that is defined in the report.
for example: on the main dashboard the date is filtered from 01/08/2019 to 31/08/2019 the date are passing to the report and the report are showing the right data and the right date when downloading the report - the data item sowing the default date (LAST 30 DAYS).

The strange thing is when I’m checking and downloading the report to PDF via the Dundas GUI, everything is right and show the correct data.

so I’m thinking there is something not right on the export script.
can someone help me with the script?

Dundas support can you help me create the script like the script behind the GUI?

I saw this document but it’s not helping me - https://www.dundas.com/support/developer/script-library/export/exporting-with-parameters

I will attach the script in another post.

Thanks in advance

// Get the export service.
var exportService = this.getService(‘ExportService’);

// Get the view service.
var viewService = this.getService(‘ViewService’);

// Get the web app service.
var webAppService = this.getService(‘WebAppService’);

// Set the report id.
var reportId = ‘ac0a3aed-beb2-4983-9bb0-26971e857eab’;

var viewParameter = parentView.control.getViewParameterByName(“Pdate”);

var contextual = dundas.Utility.getContextualPageUrl(
dundas.Pages.REPORT,
{
id: reportId,
queryString: [
new dundas.KeyValuePair(dundas.constants.VIEW_OPTIONS_QUERY_STRING_KEY, dundas.ViewOptions.VIEW_ONLY),
new dundas.KeyValuePair(‘isExport’, ‘true’)
]
}
);

var shortLinkService = window.dundas.context.getService(“ShortLinkService”);

// Get the shortlink.
var shortLinkPromise = shortLinkService.getShortLink(contextual);

var paperSize;

switch(dropDownListPaperSize.value)
{
case “A3”:
paperSize = dundas.print.PaperSize.A3;
break;
case “A4”:
paperSize = dundas.print.PaperSize.A4;
break;
case “A5”:
paperSize = dundas.print.PaperSize.A5;
break;
case “CUSTOM”:
paperSize = dundas.print.PaperSize.CUSTOM;
break;
case “LEGAL”:
paperSize = dundas.print.PaperSize.LEGAL;
break;
case “LETTER”:
paperSize = dundas.print.PaperSize.LETTER;
break;
case “TABLOID”:
paperSize = dundas.print.PaperSize.TABLOID;
break;
}

var paperOrientation;

if(dropDownListPaperOrientation.value == “LANDSCAPE”)
{
paperOrientation = dundas.print.PaperOrientation.LANDSCAPE;
}
else if(dropDownListPaperOrientation.value == “PORTRAIT”)
{
paperOrientation = dundas.print.PaperOrientation.PORTRAIT;
}

shortLinkPromise.done(
function(shortLink)
{

var fullLinkAddress = dundas.Utility.getContextualPageUrl(dundas.Pages.LINK, {
    "queryString": [new dundas.KeyValuePair(dundas.constants.SHORT_LINK_QUERY_STRING_KEY, shortLink)]
});



// Create the export request.
var exportRequest = 
    new dundas.export.ExportRequest(
      {
        // PDF provider id.
        providerId: dundas.constants.STANDARD_PDF_EXPORT_PROVIDER_ID,
        viewId: reportId,
      });

exportRequest.viewUrl = fullLinkAddress;

exportRequest.parameterValues =
  [
  	new dundas.data.SingleStringValue( { parameterId: dundas.export.PdfPropertyIds.ORIENTATION, value: paperOrientation  }), 
  	new dundas.data.SingleStringValue( { parameterId: dundas.export.PdfPropertyIds.PAPER_SIZE, value: paperSize  })

  ];

// Get the perform export promise.
var exportPromise = 
    exportService.performExport(exportRequest);

// Setup a loading dialog.
viewService.showLoadingRestCall(exportPromise);

exportPromise.done(
  function(exportId)
    {
        // Get the Url for the export file.
        var exportFileUrl =
            webAppService.getExportResultUrl(exportId);

        // Force the browser to download the file.  
        window.location.replace(exportFileUrl);
    }
);

}
);

When exporting using a script, you have to add the view parameter to the export as well.

Please try adding the following script after you assign the report ID to its variable:

  1. In the contextual variable, modify the query string to be assigned to queryString as we’re assigning it prior in the script.
  2. My currentValues variable is simply a static date to test if it’s working. You will have to add some script to convert the default date that the view parameter retrieves to the correct format. You can find the various view parameter formats here.

The Range Date filter’s default format is: Mon Jun 30 2014 20:00:00 GMT-0400 (Eastern Daylight Time)

// Get the base view service.

var dvs = this.getService(‘BaseViewService’);

// Takes care of adding the filter to the export request FROM HERE

var currentValues = “”;

var viewParameterValue = dvs.currentView.control.viewParameters[1].parameterValue;

if (viewParameterValue.token) {

// Covers the All token

currentValues = “$*$”;

} else {

// This format works for Range Date filter

// The viewParameters array index depends on how many viewParameters are on the Dashboard

//Sending a specific Date Range for testing

currentValues = “2011-05-01~2011-06-03”;

/*this.parentView.control.viewParameters[1].parameterValue.lowerBoundaryValue + ‘~’

  • this.parentView.control.viewParameters[1].parameterValue.upperBoundaryValue ;

} */

var queryString = [new dundas.KeyValuePair(dundas.constants.EDIT_QUERY_STRING_KEY, “false”),

new dundas.KeyValuePair(dundas.constants.VIEW_OPTIONS_QUERY_STRING_KEY, dundas.ViewOptions.VIEW_ONLY),

new dundas.KeyValuePair(dundas.constants.IS_EXPORT_QUERY_STRING_KEY, “true”),

new dundas.KeyValuePair("$viewParameter1", currentValues)]; //TODO: Replace “$viewParameter1” with “$viewParameterScriptNameOnReport”

// TO HERE

This will add the view parameter you are trying to filter by to the export request resulting in an exported filtered report.

1 Like