How to generate the Free Text Invoice report from X++

Hi guys,

I’m trying to generate the Free Text Invoice from X++.

Is this possible, could you please help? Thanks!

Hello,
I probably solved it in this way

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

Hi @FrancescoParis8, welcome to the community!

The code you sent will generate the report in memory stream. Here is the example of the method used for printing Free Text Invoice to one of Docentric print destinations:

       CustInvoiceJour custInvoiceJour;

        // TODO: (1) Select the sample Free text invoice journal record.
        select firstonly custInvoiceJour where custInvoiceJour.InvoiceId == 'FTI-00000013';

        Args args = new Args();
        args.record(custInvoiceJour);

        FreeTextInvoiceController controller = new FreeTextInvoiceController();
        
        // TODO: (2) Change the name SSRS Report Design if needed.
        controller.parmReportName(PrintMgmtDocType::construct(PrintMgmtDocumentType::SalesFreeTextInvoice).getDefaultReportFormat());
        controller.parmArgs(args);
        
        FreeTextInvoiceContract rdpContract = controller.parmReportContract().parmRdpContract();
        rdpContract.parmCustInvoiceJourRecId(custInvoiceJour.RecId);
        rdpContract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo());
        
        // Set the Docentric Generate DS print destination settings.
        SRSPrintDestinationSettings pds = controller.parmReportContract().parmPrintSettings();
        pds.printMediumType(SRSPrintMediumType::GenerateDataSource_DC);
        
        // TODO: (3) Set Design and Preview languages if needed.
        pds.parmGenerateDSPrintDestSettings_DC().parmLanguageId(custInvoiceJour.LanguageId);
        pds.parmGenerateDSPrintDestSettings_DC().parmPreviewLanguages('fr,de,it,es');
        
        SalesFormLetter_FreeText salesFormLetter = SalesFormLetter::construct(DocumentStatus::FreeTextInvoice);
        salesFormLetter.proforma(false);
        salesFormLetter.usePrintManagement(false);
        salesFormLetter.parmUseUserDefinedDestinations(true);
        salesFormLetter.updatePrinterSettingsFormLetter(controller.parmReportContract().parmPrintSettings().pack(), PrintSetupOriginalCopy::Original);

        args.caller(salesFormLetter);
        args.parmEnumType(enumNum(PrintCopyOriginal));
        args.parmEnum(PrintCopyOriginal::Original);

        controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);
        controller.parmShowDialog(false);
        controller.startOperation();

You can find examples like these at the end of most of our DSP classes within a main method.

If you want to find out more about generating reports as byte arrays, you can check our two blog posts:
Generate SSRS Report as Byte Array (docentric.com)
Generate Sales Invoice Proforma as Byte Array (docentric.com)