How to generate the Sales quotation report from X++

Hi guys,

I’m trying to generate the Sales quotation report (SalesQuotation.Report) from X++.

Is this possible, could you please help? Thanks!

Hi John,

Printing Sales quotation from code is not straightforward at all! Namely, printing without using Print management is possible only if you use the SalesQuotationEditLinesForm_Sales_Send class, please see below. Also note that I used the DocSrsReportGenerator class, which you can find in Docentric Free Edition, but it can also be done without it. The DocSrsReportGenerator class only sets up the Docentric Memory as the target print destination and utilizes the RenderingComplete event of the SrsReportRunController class. Learn more about DocSrsReportGenerator class >>

public static void main(Args _args)
{
    // TODO: (1) Select the sample journal record.
    // We will just select the first posted quotation.
    CustQuotationJour custQuotationJour;
    select firstonly custQuotationJour;

    // Add it as the context record, which is going to be printed.
    Args args = new Args();
    args.record(custQuotationJour);
    args.parmEnumType(enumNum(PrintCopyOriginal));
    args.parmEnum(PrintCopyOriginal::OriginalPrint);
        
    // TODO: (2) Change the name SSRS Report Design if needed.
    SalesQuotationController salesQuotationController = SalesQuotationController::construct();
    salesQuotationController.parmReportName(PrintMgmtDocType::construct(PrintMgmtDocumentType::Quotation).getDefaultReportFormat());
    salesQuotationController.parmArgs(args);

    // Set the report data contract with parameters.
    SalesQuotationContract salesQuotationContract = salesQuotationController.parmReportContract().parmRdpContract();
    salesQuotationContract.parmRecordId(custQuotationJour.RecId);
    salesQuotationContract.parmTableId(custQuotationJour.TableId);

    // Inicilaze SalesQuotationEditLinesForm_Sales_Send class instance and set NOT to use Print Management.
    SalesQuotationEditLinesForm_Sales_Send salesQuotationEditLinesForm_sales = new SalesQuotationEditLinesForm_Sales_Send();
    salesQuotationEditLinesForm_sales.usePrintManagement(false);
    args.caller(salesQuotationEditLinesForm_sales);

    DocSrsReportGenerator reportGenerator = new DocSrsReportGenerator(salesQuotationController);
    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);

    // Since the Sales quotation is printed via SalesQuotationEditLinesForm_Sales_Send class, we need to update its print settings.
    salesQuotationEditLinesForm_sales.updatePrinterSettingsFormLetter(reportGenerator.getPrintDestinationSettings().pack());

    // Start the report execution and wait until the report content is not generated.
    container generatedSalesQuotation = reportGenerator.generateReport();
    using (System.IO.MemoryStream reportMemoryStream = DocGlobalHelper::convertContainerToMemoryStream(generatedSalesQuotation))
    {
        DocFileMngHelper::sendFileToUser(reportMemoryStream,"SalesQuotation.pdf");
    }
}

Please let me know if this worked for you?

Best regards,
Jernej