AX 2012 / D365FnO – HOW TO CREATE NEW DESIGN OF STANDRAD SALES INVOICE REPORT IN X++

D365fno-PostImage

This article describes how we can create new design of sales invoice report with some custom fields in D365FO using X++.

Adding a new sales invoice report design with some extra custom fields is a very common requirement of customers. In this blog post, I’ll try to describe how we can do this in D365FO using x++.

Sales invoice report tables extension.

First of all identified the required fields that you need in the report new design and create extension of report data source tables (SalesInvoiceHeaderFooterTmp, SalesInvoiceTmp) and add these fields in required table.

Sales invoice data source tables

Copy the SalesInvoice report in you package and rename as SalesInvoiceExt.
Add the new design in SalesInvoiceExt report under designs node like CustomReport. For reference see the below screen-shot. Add the custom fields on your CustomReport design as per requirements.

Create new class PrintMgmtDocTypeSalesInvoiceReport.

Create new class PrintMgmtDocTypeSalesInvoiceReport copy the below code and paste in the class and save it.

class PrintMgmtDocTypeSalesInvoiceReport
{
    [SubscribesTo(classStr(PrintMgmtDocType), delegateStr(PrintMgmtDocType, getDefaultReportFormatDelegate))]
    public static void PrintMgmtDocType_getDefaultReportFormatDelegate(PrintMgmtDocumentType _docType, EventHandlerResult _result)
    {
        switch (_docType)
        {
            case PrintMgmtDocumentType::SalesOrderInvoice:
                _result.result(ssrsReportStr(SalesInvoiceExt, CustomReport));
            break;
        }
    }
}

Create new class SalesInvoiceControllerExt.

Create new class SalesInvoiceControllerExt and extends it from SalesInvoiceController copy the below code and paste in the class and save it.

class SalesInvoiceControllerExt extends SalesInvoiceController
{
    public static SalesInvoiceControllerExt construct()
    {
        return new SalesInvoiceControllerExt();
    }

    public static void main(Args _args)
    {
        SrsPrintMgmtFormLetterController controller = new SalesInvoiceControllerExt();
        controller.parmReportName(PrintMgmtDocType::construct(PrintMgmtDocumentType::SalesOrderInvoice).getDefaultReportFormat());
        controller.parmArgs(_args);
        controller.parmShowDialog(false);
        SalesInvoiceControllerExt::startControllerOperation(controller, _args);
    }

    protected static void startControllerOperation(SrsPrintMgmtFormLetterController _controller, Args _args)
    {
        _controller.parmShowDialog(false);
        _controller.startOperation();
    }

    protected void outputReport()
    {
        SRSCatalogItemName  reportDesign;
        reportDesign = ssrsReportStr(SalesInvoiceExt, CustomReport);
        this.parmShowDialog(false);
        this.parmReportName(reportDesign);
        this.parmReportContract().parmReportName(reportDesign);
        formletterReport.parmReportRun().settingDetail().parmReportFormatName(reportDesign);
        super();
    }

}

Create new class SalesInvoiceDP_Extension.

Let’s start with a report data provider class. First we create a new class SalesInvoiceDP_Extension and extend it from the standard SalesInvoiceDP. In this case, we can add additional fields that are relevant only for our report.

[ExtensionOf(classStr(SalesInvoiceDP))]
final class SalesInvoiceDP_Extension
{
    // populateSalesInvoiceHeaderFooterTmp method is use to insert values into SalesInvoiceHeaderFooterTmp table.
    protected void populateSalesInvoiceHeaderFooterTmp(CustInvoiceJour _custInvoiceJour, CompanyInfo _companyInfo)
    {

        salesInvoiceHeaderFooterTmp.DONumber = 'DONumber';
        salesInvoiceHeaderFooterTmp.SalesTaker = 'SalesTaker';

        next populateSalesInvoiceHeaderFooterTmp(_custInvoiceJour, _companyInfo);
    }
    // populateSalesInvoiceTmp method is use to insert values into SalesInvoiceTmp line table.
    protected void populateSalesInvoiceTmp(CustInvoiceJour _custInvoiceJour,
        CustInvoiceTrans _custInvoiceTrans,
        TaxSpec _taxSpec,
        CustPaymSchedLine _custPaymSchedLine,
        CustTrans _prepaymentCustTrans,
        TaxTrans _prepaymentTaxTrans)
    {
        TaxTrans taxTrans;
        select taxTrans
        where taxTrans.SourceTableId == tableNum(CustInvoiceTrans)
        && taxTrans.SourceRecId  == _custInvoiceTrans.RecId;

        SalesInvoiceTmp.TaxValueUsr = taxTrans.TaxValue;
        SalesInvoiceTmp.TaxAmountUsr = taxTrans.TaxAmount;

        next populateSalesInvoiceTmp(_custInvoiceJour, _custInvoiceTrans, _taxSpec, _custPaymSchedLine, _prepaymentCustTrans, _prepaymentTaxTrans);
    }

}

View the report custom design.

To view the report custom design create the extension of SalesInvoiceOriginal menu item and set the object as controller class SalesInvoiceControllerExt save and deploy the report and build the project.

This site uses cookies to offer you a better browsing experience. By browsing this website, you agree to our use of cookies.