Customizing the Check Report via Extensions in Dynamics 365 for Operations

By Tim Pypa | October 11, 2017

Recently I was asked to customize the Cheque_US report in Dynamics 365 for Operations. Based on this guidance from Microsoft I expected it to be a relatively easy and straightforward process. Here’s what I did to customize the check report via extensions:

  1. Duplicate the Cheque_US SSRS report to a model that extends the Application Suite model.

I called my new report MyCheque_US and added some text to indicate that it was the custom report—that way I could tell at a glance if I was looking at the stock report or my custom report.

  1. Create a new class MyChequeController that extends the ChequeController class in the same custom model.

Copy the main() method from ChequeController, and update it to use the report name for MyCheque_US:

class MyChequeController extends ChequeController
{
    public static MyChequeController construct()
    {
        return new MyChequeController();
    }

    
    public static void main(Args _args)
    {
        MyChequeController controller = new MyChequeController();
        controller.parmArgs(_args);
        controller.deleteTempData();
        //controller.parmReportName(controller.getChequeReport());
        controller.parmReportName(ssrsReportStr(MyCheque_US, Report));
        controller.parmShowDialog(false);
        controller.parmDialogCaption("@SYS24090");
        controller.startOperation();
    }

}
  1. Extend the Cheque_US output menu item in the same custom model.

Set the Object property to refer to MyChequeController rather than ChequeController

The Object property is changed to MyChequeController rather than ChequeController.

I then compiled my solution and deployed the MyCheque_US report, and when I generated a payment everything worked! Well, almost everything: the custom report displayed as a blank page. I verified that if I switched back to the stock controller code controller.parmReportName(controller.getChequeReport()) then everything printed fine, but if I ran the same data through the MyCheque_US report it would fail every time.

After some digging I came to a startling conclusion. Based on its name and signature, I was trusting getChequeReport() to be a true accessor method:

getChequeReport() was trusted to be a true accessor method.

When I inspected the method itself, though, it quickly became apparent that it was something very different:

    /// <summary>
    /// Calls the initialize method and returns a cheque report type.
    /// </summary>
    /// <returns>
    /// A cheque report type.
    /// </returns>
    public SrsCatalogItemName getChequeReport()
    {
        this.init();
        return chequeReport;
    }

ChequeController.getChequeReport() violates two method writing best practices: a method should do only one thing, and method names should reveal intention.

The giveaway that getChequeReport() does more than one thing is the “and” in the documentation summary. If you need to use the word “and” when describing what a method does, the method does too many things!

Admittedly, the method name getChequeReport does communicate what the method returns. The problem is that it doesn’t communicate everything that the method does. Had it instead been named initAndGetChequeReport then the intent of the method would be clear (and would clearly indicate that the method does too many things.)

In hindsight it would have been better to split getChequeReport() up into two methods, one to initialize the report and the other to retrieve the report name. In the end I decided that the least risky way to solve my problem was to keep the stock call to parmReportName() in place, and follow it up with another call to parmReportName() to direct execution to my custom report:

    public static void main(Args _args)
    {
        MyChequeController controller = new MyChequeController();
        controller.parmArgs(_args);
        controller.deleteTempData();
        controller.parmReportName(controller.getChequeReport());
        controller.parmReportName(ssrsReportStr(MyCheque_US, Report));
        controller.parmShowDialog(false);
        controller.parmDialogCaption("@SYS24090");
        controller.startOperation();
    }

Now the report gets properly initialized, and my custom report design is used to generate the check.


Under the terms of this license, you are authorized to share and redistribute the content across various mediums, subject to adherence to the specified conditions: you must provide proper attribution to Stoneridge as the original creator in a manner that does not imply their endorsement of your use, the material is to be utilized solely for non-commercial purposes, and alterations, modifications, or derivative works based on the original material are strictly prohibited.

Responsibility rests with the licensee to ensure that their use of the material does not violate any other rights.

Start the Conversation

It’s our mission to help clients win. We’d love to talk to you about the right business solutions to help you achieve your goals.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!