Adding a Custom Document Type to Print Management in D365 F&O Using Chain of Command

 

Print Management in D365 FO

Introduction

Print Management in D365 F&O only shows the document types a module's node class knows about. If you've added a custom report , a cover note, a delivery instruction, a compliance document and it won't show up as an option in Print Management setup, the fix is almost always a single Chain of Command method: getDocumentTypes().


Understanding the Scenario

Each module exposes its own Print Management node class, PrintMgmtNode_Purch for procurement documents, PrintMgmtNode_Invent for inventory and warehouse documents, and so on. Each one implements getDocumentTypes(), which returns the list of document types available for that node in the Print Management setup form. To add a custom document, you extend the base PrintMgmtDocumentType enum with a new value, then extend the relevant node class so its document list includes it.



The X++ Implementation


Chain of Command extension on PrintMgmtNode_Invent that adds several custom document types at once:


[ExtensionOf(classStr(PrintMgmtNode_Invent))]

internal final class PrintMgmtNode_Invent_CustExtension

{

    public List getDocumentTypes()

    {

        List docTypes = next getDocumentTypes();


        docTypes.addEnd(PrintMgmtDocumentType::CustCoverNote);

        docTypes.addEnd(PrintMgmtDocumentType::CustDeliveryInstruction);


        return docTypes;

    }

}


CustCoverNote and CustDeliveryInstruction are new elements you'd add on an extension of the base PrintMgmtDocumentType enum first — that step has to exist before this code will compile.



How the Code Works


next getDocumentTypes() calls the base implementation first, returning the standard list of document types for that node. The extension then appends its own entries with addEnd() and returns the combined list. Calling next first, then adding to the result, is what keeps this upgrade-safe — the standard document types are never touched, only extended.



Completing the Setup


Suggested implementation - the document type will appear in the list, but it needs a default report before anyone can actually print it. That's done separately by subscribing to PrintMgmtReportFormatPublisher's notifyPopulate delegate:


public class PrintMgmtReportFormatPublisherHelper

{

    [SubscribesTo(classStr(PrintMgmtReportFormatPublisher), delegateStr(PrintMgmtReportFormatPublisher, notifyPopulate))]

    public static void notifyPopulate()

    {

        PrintMgmtReportFormatPublisherHelper::addFormat(

            PrintMgmtDocumentType::CustCoverNote,

            ssrsReportStr(CustCoverNoteReport, Report));

    }


    private static void addFormat(PrintMgmtDocumentType _type, PrintMgmtReportFormatName _name)

    {

        PrintMgmtReportFormatPublisherHelper::addPrintMgmtReportFormat(_type, _name, _name);

    }

}


Without this step, the document type shows up in setup but has no report attached to it by default — someone would have to pick one manually every time.




Refrence - 
Class extension - Method wrapping and Chain of Command - https://learn.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/extensibility/method-wrapping-coc

Comments