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();
public static void main(Args _args)
SrsReportRunController controller = new SrsReportRunController();
CustTransOpenPerDateContract contract = new CustTransOpenPerDateContract();
SrsReportEMailDataContract emailContract = new SrsReportEMailDataContract();
ExchangeRateHelper exchangeRateHelper = new ExchangeRateHelper();
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.
We’re already discussing it in Dynamics Community forum. And it occurred that it’s about AX 2012, not D365FO.
Hello Martin, im having this issue in d365
I need also to save the pdf file (report) from D365 to local directory.I did not have issue but the file is downloaded and i should save it manually. the path given by code is ignored.
There is a solution,please ?
Thank you in advance.
The web application can’t simply connect to your local machine and change files there. Therefore your solution simply isn’t possible.
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().
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?
Hi Mohammad, I suggest you should create a thread in a discussion forum (such as at https://community.dynamics.com/) and explain your requirement in detail there. I participate in these forums and you’ll also reach other people there. And don’t forget to mention your version of AX.