Intro
Before proceeding with the working example below, we recommend to get to know the limitations of the DocSrsReportGenerator first:
The above forum post also contains a working example for the SalesPackingSlip report.
The main difference for the FreeTextInvoice report is that it has the parmUseUserDefinedDestinations() method implemented, so the implementation is different, as outlined in the above forum post about the DocSrsReportGenerator limitations.
A minor difference is that the FreeTextInvoiceController uses the updatePrinterSettingsFormLetter() method, instead of the parmPrinterSettingsFormLetter() method.
Working Example Code
Below is a working example of how to run the FreeTextInvoice report using the DocSrsReportGenerator :
public class DocPrintFreeTextInvoiceToBrowser
{
public static void main(Args _args)
{
CustInvoiceJour custInvoiceJour;
select firstonly custInvoiceJour
where custInvoiceJour.SalesId == '';
Args args = new Args();
args.record(custInvoiceJour);
args.parmEnumType(enumNum(PrintCopyOriginal));
args.parmEnum(PrintCopyOriginal::Original);
FreeTextInvoiceController freeTextInvoiceController = new FreeTextInvoiceController();
freeTextInvoiceController.parmReportName(PrintMgmtDocType::construct(PrintMgmtDocumentType::SalesFreeTextInvoice).getDefaultReportFormat());
freeTextInvoiceController.parmArgs(args);
FreeTextInvoiceContract freeTextInvoiceContract = freeTextInvoiceController.parmReportContract().parmRdpContract();
freeTextInvoiceContract.parmCustInvoiceJourRecId(custInvoiceJour.RecId);
DocSrsReportGenerator reportGenerator = new DocSrsReportGenerator(freeTextInvoiceController);
reportGenerator.setPrintDestinationSettings_DocentricReport(DocOutputFileFormat::PDF, 'FreeTextInvoice.Report');
SalesFormLetter_FreeText salesFormLetterFreeText = SalesFormLetter_FreeText::newFreeText();
salesFormLetterFreeText.printFormLetter(true);
salesFormLetterFreeText.usePrintManagement(false);
salesFormLetterFreeText.parmUseUserDefinedDestinations(true);
salesFormLetterFreeText.updatePrinterSettingsFormLetter(reportGenerator.getPrintDestinationSettings().pack(), PrintSetupOriginalCopy::Original);
args.caller(salesFormLetterFreeText);
container generatedFreeTextInvoice = reportGenerator.generateReport();
using (System.IO.MemoryStream reportMemoryStream = DocGlobalHelper::convertContainerToMemoryStream(generatedFreeTextInvoice))
{
DocFileMngHelper::sendFileToUser(reportMemoryStream, 'FreeTextInvoice.pdf');
}
}
}
If you want to print a copy instead, you need to replace the following:
- PrintCopyOriginal::Original → PrintCopyOriginal::Copy
- PrintSetupOriginalCopy::Original → PrintSetupOriginalCopy::Copy