Sunday, August 11, 2019

Adding new print management report node in D365 - code sample

public static class PrintMgmtDelegates_Extension
{
 
    /// <summary>
    ///
    /// </summary>
    /// <param name="_nodeType"></param>
    /// <param name="_result"></param>
    [SubscribesTo(classStr(PrintMgmtDelegates), delegateStr(PrintMgmtDelegates, constructPrintMgmtNodeDelegate))]
    public static void PrintMgmtDelegates_constructPrintMgmtNodeDelegate(PrintMgmtNodeType _nodeType, EventHandlerResult _result)
    {
        switch (_nodeType)
        {
            case printmgmtNOdeTYpe::Custom:

                PrintMgmtNode_Custom    printMgmtNode_Custom = new PrintMgmtNode_Custom();
                _result.result(printMgmtNode_Custom);

                break;
        }
    }

}



--------------------------------------------

[ExtensionOf(classStr(PrintMgmtHierarchy_Sales))]
final class PrintMgmtHierarchy_Sales_Extension
{
    protected List getNodesImplementation()
    {
        //List supportedNodes = new List(Types::Enum);
        var supportedNodes = next getNodesImplementation();
        supportedNodes.addEnd(PrintMgmtNodeType::Custom);
        return supportedNodes;
    }

    protected PrintMgmtNodeInstance getParentImplementation(PrintMgmtNodeInstance _nodeInstance, PrintMgmtDocumentType _docType)
    {
        PrintMgmtNodeInstance result;
        result  = next getParentImplementation(_nodeInstance, _docType);
        return result;
    }

}
----------------------------------------------

class PrintMgmtNode_Custom extends PrintMgmtNode
{
    protected str getDisplayCaptionImplementation(Common _tableBuffer)
    {
        return(strfmt("@SYS108944", _tableBuffer.caption()));
    }

    public List getDocumentTypes()
    {
        List    docTypes;

        docTypes = new List(Types::Enum);

        if (isConfigurationkeyEnabled(configurationkeynum(LogisticsBasic)))
        {
            docTypes.addEnd(PrintMgmtDocumentType::Custom);
        }

        return docTypes;
    }

    public int getIconImageResNum()
    {
        #resAppl

        return #ImagePrintManagementTrans;
    }

    public PrintMgmtNodeType getNodeType()
    {
        return PrintMgmtNodeType::Custom;
    }

    public RefTableId getReferencedTableId()
    {
        return tablenum(CustomTable);
    }

}

----------------------------------------

class PrintMgmtNode_Sales_Custom
{
    /// <summary>
    ///
    /// </summary>
    /// <param name="args"></param>
    [PostHandlerFor(classStr(PrintMgmtNode_Sales), methodStr(PrintMgmtNode_Sales, getDocumentTypes))]
    public static void PrintMgmtNode_Sales_Post_getDocumentTypes(XppPrePostArgs args)
    {
        List docTypes;
        docTypes    = new List(Types::Enum);
        docTypes    = Args.getReturnValue();
        docTypes.addEnd(PrintMgmtDocumentType::Custom);

        Args.setReturnValue(docTypes);
    }

}

----------------------


class PrintMgtDocTypeHandlersExt
{
 

    /// <summary>
    ///
    /// </summary>
    /// <param name="_docType"></param>
    /// <param name="_result"></param>
    [SubscribesTo(classStr(PrintMgmtDocType), delegateStr(PrintMgmtDocType, getDefaultReportFormatDelegate))]
    public static void PrintMgmtDocType_getDefaultReportFormatDelegate(PrintMgmtDocumentType _docType, EventHandlerResult _result)
    {
        switch (_docType)
        {
            case PrintMgmtDocumentType::Custom:
                _result.result(ssrsReportStr(SalesConfirmExt, Report));
                break;
        }
    }

    /// <summary>
    ///
    /// </summary>
    /// <param name="_docType"></param>
    /// <param name="_result"></param>
    [SubscribesTo(classStr(PrintMgmtDocType), delegateStr(PrintMgmtDocType, getQueryTableIdDelegate))]
    public static void PrintMgmtDocType_getQueryTableIdDelegate(PrintMgmtDocumentType _docType, EventHandlerResult _result)
    {
        TableId     tableId;

        switch(_docType)
        {
            case PrintMgmtDocumentType::Custom:
                tableId = tableNum(CustomTable);
                _result.result(tableId);
                break;
        }
    }

}
---------------

class SalesConfirmControllerExt extends SalesConfirmController
{
    public static SalesConfirmControllerExt construct()
    {
        return new SalesConfirmControllerExt();
    }

    public static void main(Args _args)
    {
        SrsReportRunController      formLetterController = SalesConfirmControllerExt::construct();
        SalesConfirmControllerExt   controller = formLetterController;controller.initArgs(_args, ssrsReportStr(SalesConfirmExt, Report));
     
        if (classIdGet(_args.caller()) == classNum(SalesConfirmJournalPrint))
        {
            formLetterController.renderingCompleted += eventhandler(SalesConfirmJournalPrint::renderingCompleted);
        }
     
        formLetterController.startOperation();
    }

}

----------------------

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