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

Notifications

Announcements

No record found.

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 172

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
    172 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 522 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans