Friday, September 1, 2017

Dynamics 365 - Extending Sales and Purchase Documents

I almost got it right on my first attempt.  I was recently asked to update the PO Report in Dynamics 365.  In the extension model, a report is updated by doing the following:

  1. Create table extensions if extra data is required
  2. Create a copy of the report you wish to update
  3. Create a derived class of the controller that handles the report you are updating.
  4. Change the main method to point to the new report.
  5. Create a derived class of the Data Provider and override the processReport method to gather any new data required (don't forget to call super() to perform the original queries).
  6. Repoint the report's data sources to the derived data provider.
  7. Reformat the report as required.
  8. Extend all menu items that point to the original controller.  Repoint them to the new controller (object property).
  9. Compile the project, deploy the report and perform a synchronization.

In most cases, this is all that would be required to update an existing report.  However, the Purchasing and Sales Documents maintain a reference to the original document under print management.  So, even if you process the correct controller and data provider an you are point to the correct report; Dynamics 365 will return a blank report in the original format.

In order to define the correct default, you need to update the print management setting for the document type.  The process is the same for both Sales and Purchasing


Write a delegate that adds your extended report to the list of available reports for the document type.
public class CPPrintMgtDocTypeHandlersExt
{
    [SubscribesTo(classstr(PrintMgmtDocType), delegatestr(PrintMgmtDocType, getDefaultReportFormatDelegate))]
    public static void getDefaultReportFormatDelegate(PrintMgmtDocumentType _docType, EventHandlerResult _result)
    {
        switch (_docType)
        {
            case PrintMgmtDocumentType::PurchaseOrderRequisition:
                _result.result(ssrsReportStr(CPPurchPurchaseOrder, Report));
                break;
        }
    }
}

In this case, an extended report is added to the Purchase Orders list.

Then set the report type as default for both the original and copy.  For Purchase Orders, go to Accounts Payable -> Setup -> Forms -> Form Setup. 





Then click Print management setup.  Once inside, select your document and right click.  Select New from the menu.  Fill in the other details and open the Report Format drop down.  If the delegate was set up correctly, then the new report format should appear.  Repeat these steps to add a default format for the copy as well.





1 comment:

  1. 4 years later: Depending on the scenario, step 5 can be modified to create a class extension on the data provider and use COC to populate the additional data.

    ReplyDelete