Generate Free Text Invoice Report as Memory Stream with Docentric

In this article I will explain how to create the Free Text Invoice report with Docentric. The report will then be converted into a Memory Stream.

If you need to generate a SSRS report as a byte array, you can use a utility X++ class DocSrsReportGenerator, which is delivered with Docentric Free Edition.

Printing Free Text Invoice can be done via the SalesFormLetter_FreeText class.

            Args args = new Args();
            FreeTextInvoiceController controller = new FreeTextInvoiceController();
    
            // Set the SalesFreeTextInvoice.Report as SSRS Report Design.
            controller.parmReportName(PrintMgmtDocType::construct(PrintMgmtDocumentType::SalesFreeTextInvoice).getDefaultReportFormat());
 
            // In order to have the context table we need to set args.record().
            // We will just select the first posted invoice.           
            args.record(_custInvoiceJour);            
 
            // Set the report data contract with parameters.
            FreeTextInvoiceContract contract = controller.parmReportContract().parmRdpContract();
            contract.parmCustInvoiceJourRecId(_custInvoiceJour.RecId);
 
            DocSrsReportGenerator reportGenerator = new DocSrsReportGenerator(controller);
            reportGenerator.setPrintDestinationSettings_SsrsReport(SRSReportFileFormat::PDF);
 
            // NOTE: If you want to generate the report using a Docentric template, use this line of code instead.
            // reportGenerator.setPrintDestinationSettings_DocentricReport(DocOutputFileFormat::PDF);
 
            // Initalize SalesFormLetter_FreeText class instance because there is no other way
            // NOT to use Print Management.
            SalesFormLetter_FreeText salesFormLetter = SalesFormLetter_FreeText::newFreeText();
            salesFormLetter.printFormLetter(NoYes::Yes);
            salesFormLetter.usePrintManagement(false);
            salesFormLetter.parmUseUserDefinedDestinations(true);            salesFormLetter.updatePrinterSettingsFormLetter(controller.parmReportContract().parmPrintSettings().pack());
 
            args.caller(salesFormLetter);
            args.parmEnumType(enumNum(PrintCopyOriginal));
            args.parmEnum(PrintCopyOriginal::OriginalPrint);
            controller.parmArgs(args);
          
            // Start the report execution and wait until the report content is not generated.
            container generatedInvoice = reportGenerator.generateReport();

            // Convert container to a memory stream.
            System.IO.MemoryStream generatedReportMemoryStream = DocGlobalHelper::convertContainerToMemoryStream(generatedInvoice);

Docentric provides two functions to convert a D365FO containers to .NET byte arrays or memory streams.

// Convert container to a byte array.
System.Byte[] generatedReportByteArray = 
    DocGlobalHelper::convertContainerToBytes(generatedReport);
// Convert container to a memory stream.
System.IO.MemoryStream generatedReportMemoryStream =
    DocGlobalHelper::convertContainerToMemoryStream(generatedReport);

Lascia un commento