Printing reports from code in D365FO

A comment below my blog post Printing reports from code in AX2012 asked me to provide an example for D365FO. Here is it.

The code is virtually identical. Only writing a file to a shared folder doesn’t make a good sense in cloud, therefore I changed the code to return the file to user for download.

SrsReportRunController          controller = new SrsReportRunController();
SysUserLicenseCountRDPContract  rdpContract = new SysUserLicenseCountRDPContract();
SRSPrintDestinationSettings     settings;
 
// Define report and report design to use
controller.parmReportName(ssrsReportStr(SysUserLicenseCountReport, Report));
// Use execution mode appropriate to your situation
controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);
// Suppress report dialog
controller.parmShowDialog(false);
 
// Explicitly provide all required parameters
rdpContract.parmReportStateDate(systemDateGet());
controller.parmReportContract().parmRdpContract(rdpContract);
 
// Change print settings as needed
settings = controller.parmReportContract().parmPrintSettings();
settings.printMediumType(SRSPrintMediumType::File);
settings.fileFormat(SRSReportFileFormat::Excel);
settings.fileName('UserLicenseCount.xlsx');
 
// Execute the report
controller.startOperation();

2 Comments

  1. Hi Martin,
    public static void main(Args _args)
    {
    SrsReportRunController controller = new SrsReportRunController();
    CustTransOpenPerDateContract contract = new CustTransOpenPerDateContract();
    SrsReportEMailDataContract emailContract = new SrsReportEMailDataContract();
    ExchangeRateHelper exchangeRateHelper = new ExchangeRateHelper();
    SRSPrintDestinationSettings settings;

    controller.parmReportName(ssrsReportStr(FreeTextInvoice, Report));

    controller.parmExecutionMode(SysOperationExecutionMode::ScheduledBatch);

    controller.parmShowDialog(false);
    exchangeRateHelper.parmFromCurrency(“USD”);

    controller.parmReportContract().parmRdpContract(contract);

    settings = controller.parmReportContract().parmPrintSettings();
    settings.printMediumType(SRSPrintMediumType::File);
    settings.fileFormat(SRSReportFileFormat::PDF);
    settings.overwriteFile(true);
    settings.fileName(@’C:\Users\sst_siddhant\Desktop\PDFfile.pdf’);

    controller.startOperation();
    }
    I am getting an error –
    1.A currency to convert from is required to retrieve exchange rate information.
    2.Microsoft.Dynamics.Ax.Xpp.ErrorException: Exception of type ‘Microsoft.Dynamics.Ax.Xpp.ErrorException’ was thrown.
    What will be the solution for this issue.

    Thank You
    Siddhant Singh

Leave a Reply

Your email address will not be published.