I was fulfilling the requirement to customize SSRS report using extension in D365FO. Extending the data set and customizing the design using extension approach in D365FO is difficult but a journey full of learning.

Previously, in Microsoft Dynamics AX 2012, it was easy to add your custom code and to customize the design. But, in Microsoft Dynamics 365 for Finance and Operations, it is difficult and more logical than before.

In this tutorial, I will show you how to customize & extend data set and design of Free Text Invoice report. Let’s start.

I have to add two fields in the table and to show these fields in Free Text Invoice report. If you have come across the Free Text Invoice report. You may have noticed that it uses contract class, controller class, DP class and print management class to generate the report.

What you have to do to customize SSRS report using extension in D365FO is to create the extension of table, implement the events to insert the data into the extended fields, customize the design, extend the controller class and subscribe to the delegate of print management document type class to re-route the print management to execute your new design.

I have done the following steps:

  • Create extension of FreeTextInvoiceTmp table and add the field i.e. TotalAmounInWords
  • Create a class named FreeTextInvoiceController_Events to implement the event handler methods
  • Copy the post handler event method of processReport() of FreeTextInvoiceDP class and paste in the class created in previous step.
    • NOTE: You can also use the OnInserting event of table instead of processReport() of DP class.
  • Write the following logic to insert the data into the
    TotalAmounInWords field we have created:
class FreeTextInvoiceController_Events
{
    [PostHandlerFor(classStr(FreeTextInvoiceDP), methodStr(FreeTextInvoiceDP, processReport))]
    public static void FreeTextInvoiceDP_Post_processReport(XppPrePostArgs args)
    {
        FreeTextInvoiceDP dpInstance = args.getThis() as FreeTextInvoiceDP;
        FreeTextInvoiceHeaderFooterTmp freeTextInvoiceHeaderFooterTmp = dpInstance.getFreeTextInvoiceHeaderFooterTmp();
        FreeTextInvoiceTmp freeTextInvoiceTmp = dpInstance.getFreeTextInvoiceTmp();
        ttsbegin;
        while select forUpdate freeTextInvoiceTmp
        {
            freeTextInvoiceTmp.TotalAmounInWords = numeralsToTxt(freeTextInvoiceTmp.InvoiceAmount);
            freeTextInvoiceTmp.update();
        }
        ttscommit;
    }
}
  • Find out the FreeTextInvoice report in the AOT,
  • Right-click the report and click Duplicate in project.
  • Customize the design and add TotalAmountInWords field as per your requirements
  • Create another class named FreeTextInvoiceControllerExt which extends the FreeTextInvoiceController class. Override the main() method. Give the new report and it’s design name in it.
  • Add the following logic in FreeTextInvoiceControllerExt class:
class FreeTextInvoiceControllerExt extends FreeTextInvoiceController
{
    public static FreeTextInvoiceControllerExt construct()
    {
        return new FreeTextInvoiceControllerExt();
    }

    public static void main(Args _args)
    {
        SrsReportRunController formLetterController = FreeTextInvoiceControllerExt::construct();
        FreeTextInvoiceControllerExt controller = formLetterController;
        controller.parmReportName(ssrsReportStr(FreeTextInvoiceCopy, Report));
        controller.parmArgs(_args);
        controller.startOperation();
    }
}
  • Create another class named PrintMgtDocTypeHandlersExt
  • Add a method in it which subscribes to the event delegate of PrintMgmtDocType class to re-route the report from the default to this customized report
  • Add the following logic in PrintMgtDocTypeHandlersExt class:
class PrintMgtDocTypeHandlersExt
{
    [SubscribesTo(classstr(PrintMgmtDocType), delegatestr(PrintMgmtDocType, getDefaultReportFormatDelegate))]
    public static void getDefaultReportFormatDelegate(PrintMgmtDocumentType _docType, EventHandlerResult _result)
    {
        switch (_docType)
        {
            case PrintMgmtDocumentType::SalesFreeTextInvoice:
                _result.result(ssrsReportStr(FreeTextInvoiceCopy, Report));
                break;
        }
    }
}
  • Create extension of the following menu items which executes report:
    • FreeTextInvoiceCopy
    • FreeTextInvoiceOriginal
  • Change the controller class name in the Object property of the extended menu items to the FreeTextInvoiceControllerExt class created above
  • Save, build and synchronize and deploy the project/reports.

In this way, we can customize SSRS report using extension in D365FO

If you found any ambiguity or a better solution, please feel free to ask.

Blog: Click here

YouTube: Click here

GitHub: Click here

Take the stones people throw at you and use them to build a monument. – Robin Sharma

The post Customize SSRS report using extension in D365FO appeared first on NevoiTech Blog.