web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Missing parameters while print custom invoice

(0) ShareShare
ReportReport
Posted on by 174

Can somebody tell me what am I missing in this code? I'm creating salesInvoices yet the invoices do not have the title parameters so I'm missing data. instead of "Invoice No. 1234" i have only "No. 1234"  like the documentTitle() is not involved in this, and the second thing all invoices are created in my local language there is no translation like when I print it normally from AX form using PrintOriginal etc.

public void saveSalesInvoiceToPdfFile(RecId _refRecId)
    {
        if (_refRecId)
        {
            PrintMgmtReportFormatName printMgmtReportFormatName = PrintMgmtDocType::construct(PrintMgmtDocumentType::SalesOrderInvoice).getDefaultReportFormat();
            SalesInvoiceContract salesInvoiceContract = new SalesInvoiceContract();
            salesInvoiceContract.parmRecordId(_refRecId);
            SalesInvoiceController SalesInvoiceController = SalesInvoiceController::construct();
            SalesInvoiceController.parmReportName(printMgmtReportFormatName);
            SalesInvoiceController.parmExecutionMode(SysOperationExecutionMode::Synchronous);
            SalesInvoiceController.parmShowDialog(false);

            SalesInvoiceController.parmReportContract().parmRdpContract(salesInvoiceContract);
            SalesInvoiceController.parmReportContract().parmReportExecutionInfo(new SRSReportExecutionInfo());
            SalesInvoiceController.parmReportContract().parmReportServerConfig(SRSConfiguration::getDefaultServerConfiguration());
            
            var args = new Args();
            args.parmEnum(PrintCopyOriginal::Original);
            args.record(custInvoiceJour::findRecId(_refRecId));
            SalesInvoiceController.parmArgs(args);
            
            SRSPrintDestinationSettings printerSettings = SalesInvoiceController.parmReportContract().parmPrintSettings();
            printerSettings.printMediumType(SRSPrintMediumType::File);
            printerSettings.fileFormat(SRSReportFileFormat::PDF);
            printerSettings.parmFileName(filePath   fileName);
            printerSettings.overwriteFile(true);

            SRSReportRunService srsReportRunService = new SrsReportRunService();
            srsReportRunService.getReportDataContract(SalesInvoiceController.parmReportContract().parmReportName());
            srsReportRunService.preRunReport(SalesInvoiceController.parmReportContract());
            Map reportParametersMap = srsReportRunService.createParamMapFromContract(SalesInvoiceController.parmReportContract());
            Microsoft.Dynamics.AX.Framework.Reporting.Shared.ReportingService.ParameterValue[]  parameterValueArray = SrsReportRunUtil::getParameterValueArray(reportParametersMap);

            SRSProxy srsProxy = SRSProxy::constructWithConfiguration(SalesInvoiceController.parmReportContract().parmReportServerConfig());

            System.Byte[] reportBytes = srsproxy.renderReportToByteArray(SalesInvoiceController.parmreportcontract().parmreportpath(), parameterValueArray, printerSettings.fileFormat(), printerSettings.deviceinfo());

            if (reportBytes)
            {
                System.IO.Stream stream = new System.IO.MemoryStream(reportBytes);
                System.IO.FileStream fileStream = new System.IO.FileStream(filePath   fileName, System.IO.FileMode::Create, System.IO.FileAccess::ReadWrite);
                stream.CopyTo(fileStream);
                fileStream.Close();
            }
        }
    }

I have the same question (0)
  • huijij Profile Picture
    19,811 on at

    Hi RadekM,

    Did you get any error information?

  • RadekM Profile Picture
    174 on at

    No errors are present. I did already fix it finding the missing parameters that were not set.

    Needed to add manually the right labels from DocumentTitle() and add parmLabelLangId so the invoices is translated correctly according to langId.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 514 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 390

#3
Adis Profile Picture

Adis 266 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans