D365 FO - New document type in Print Management setup

Hello everyone, today we'll look at how to add a document type to the print management configuration in Dynamics 365 Finance.



The first step should be to extend the base enum print management document type [PrintMgmtDocumentType] and add a new element there.

The second step should be to extend the PrintMgmtNode class based on the module where you want to add the custom document. We will add a document to the accounts receivable print management configuration as an example.

 

[ExtensionOf(classStr(PrintMgmtNode_Sales))]

final class PrintMgmtNode_Sales_Extension

{

    public List getDocumentTypes()

    {

        List documentTypes;

 

        documentTypes = new List(Types::Enum);

 

        documentTypes = next getDocumentTypes();

 

        documentTypes.addEnd(PrintMgmtDocumentType::CustomDocument);

                            

        return documentTypes;

    }

 

}

 

Subscribe to the NotifyPopulate function of the PrintMgmtReportFormatPublisher class to insert a default report into a custom document.

 

public class PrintMgmtReportFormatPublisherUtil

{

   [SubscribesTo(classstr(PrintMgmtReportFormatPublisher),

                 delegatestr(PrintMgmtReportFormatPublisher, notifyPopulate))]

    public static void notifyPopulate()

    {

        #PrintMgmtSetup

 

        void addFormat(PrintMgmtDocumentType _type, PrintMgmtReportFormatName _name,

                   PrintMgmtReportFormatCountryRegionId _countryRegionId = #NoCountryRegionId)

        {

            PrintMgmtReportFormatPublisherUtil::addPrintMgmtReportFormat(_type, _name, _name,

               _countryRegionId);

        }

 

        addFormat(PrintMgmtDocumentType::CustomDocument,

                      ssrsReportStr(CustomReport, Report));

    }

 

    private static void addPrintMgmtReportFormat(

        PrintMgmtDocumentType _type,

        PrintMgmtReportFormatName _name,

        PrintMgmtReportFormatDescription _description,

        PrintMgmtReportFormatCountryRegionId _countryRegionId,

        PrintMgmtReportFormatSystem _system = false,

        PrintMgmtSSRS _ssrs = PrintMgmtSSRS::SSRS)

    {

        PrintMgmtReportFormat printMgmtReportFormat;

 

        select firstonly printMgmtReportFormat

            where printMgmtReportFormat.DocumentType == _type

                && printMgmtReportFormat.Description == _description

                && printMgmtReportFormat.CountryRegionId == _countryRegionId;

 

        if (!printMgmtReportFormat)

        {

            // Add the new format

            printMgmtReportFormat.clear();

            printMgmtReportFormat.DocumentType = _type;

            printMgmtReportFormat.Name = _name;

            printMgmtReportFormat.Description = _description;

            printMgmtReportFormat.CountryRegionId = _countryRegionId;

            printMgmtReportFormat.System = _system;

            printMgmtReportFormat.ssrs = _ssrs;

            printMgmtReportFormat.insert();

        }

    }

}

 

To get the default report, subscribe the delegate getDefaultReportFormatDelegate and getQueryTableIdDelegate of class PrintMgmtDocType.

 

public class PrintMgmtDocTypeEventHandler

{

 

    [SubscribesTo(classStr(PrintMgmtDocType), delegateStr(PrintMgmtDocType,

                  getDefaultReportFormatDelegate))]

    public static void getDefaultReportFormat(PrintMgmtDocumentType _docType, EventHandlerResult

                                              _result)

    {

        switch (_docType)

        {

                case PrintMgmtDocumentType::CustomDocument:

                _result.result(ssrsReportStr(CustomReport, Report));

                break;

        }

    }

 

 

    [SubscribesTo(classStr(PrintMgmtDocType), delegateStr(PrintMgmtDocType,

     getQueryTableIdDelegate))]

    public static void PrintMgmtDocType_getQueryTableIdDelegate(PrintMgmtDocumentType _docType,

                                                                 EventHandlerResult _result)

    {

        TableId tableId;

         switch (_docType)

        {

            case PrintMgmtDocumentType::CustomDocument:

                tableId = tableNum(CustomReportTemp);

                _result.result(tableId);

                break;

        }

    }

 }

 

1 comment:

  1. I'm not able to use query ranges for print management. Ranges are working fine with standard reports but newly added reports not working fine with ranges. I tried to save my report as a PDF instead of screen print but it's always showing screen printing rather than downloading that report as a pdf. I have already subscribed getQueryTableIdDelegate() method. Any idea why it is not working?

    ReplyDelete

Powered by Blogger.