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
// Suppress report dialog
// Explicitly provide all required parameters
// Change print settings as needed
settings = controller.parmReportContract().parmPrintSettings();
// Execute the report


  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));




    settings = controller.parmReportContract().parmPrintSettings();

    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

  2. if you are using the FreeTextInvoice Report, you must populate the journal RecId from which to print the report. You are not putting anything in that contract. So how must D365 know which record to use for the report?

    • FreeTextInvoice reports uses FreeTextInvoiceContract, which has a method called parmCustInvoiceJourRecId(). The value is normally set in FreeTextInvoiceController.preRunModifyContract().

  3. It may be little late for comment but i am trying use this code. My scenario is slightly different.
    I don’t have report to print but I have HTML stream to print. I want to send that stream on print using Documentcontract but DocumentContractType does’t support HTML. Is there a way I can use this code to print that HTML on printer?

  4. I tried to use this code. Preview doesn’t show but download doesn’t start. Some Browser Settings are needed? D365FO App Version is 10.0.33(10.0.1549.38).

      • Thanks for replying.
        No file has been downloaded.
        I tried to download a PDF file of On-hand inventory report, changing destination on the dialog(no customize), but not downloaded. I think i should resolve this, and your code will go well. I’m going to ask mircosoft.

Leave a Reply

Your email address will not be published. Required fields are marked *