Search This Blog

Thursday, February 16, 2012

AX2012 Configure Print Management for SSRS Report


Configure Print Management For the Report in AX2012.

1.     Create the SSRS Report.
2.     Updated based on the requirements from FDD either AutoDesign or Create a prcesion Design and change the name of the precisionDesign to standard name as ’Report’.
3.     Deploy the Report.

When we execute this report we should use the print management functionality for getting the details to print original or copy settings from print management.

In our Example I created the report called as internal Delivery Note from WMSJournal.
This report must be executed from the Journal Form, and while posting the journal if the journal is success then we have to print the original copy of the report.

Step 1-
Creating the Report with the name as InternalDeliveryNote and I created the precision Design and updated that Design name as ’Report’ and Deployed the report.
I have build one query for this report using WMSJournalTable and WMSJournalTrans.
Step 2-
 We have to finalize from which Module we have to print, I have descided to print from invent Module.
     Add the Enum  element in the PrintMgmtNodeType as –InternalDeliveryNote
     Add the Enum Element in the PrintMgmtDocumentType as-InternalDeliveryNote

Added the Code in the following classes

Class -PrintMgmtHierarchy_Invent
Methods-GetNodesImplementation, getParentImplementation

protected List getNodesImplementation()
{
    List supportedNodes = new List(Types::Enum);
    ;

    // Add allowable nodes for this hierarchy
    supportedNodes.addEnd(PrintMgmtNodeType::Invent);
    supportedNodes.addEnd(PrintMgmtNodeType::CustTable);
    supportedNodes.addEnd(PrintMgmtNodeType::InventTransferTable);
    supportedNodes.addEnd(PrintMgmtNodeType::SalesTable);

supportedNodes.addEnd(PrintMgmtNodeType::InternalDeliveryNote);
  

    return supportedNodes;
}

protected PrintMgmtNodeInstance getParentImplementation(PrintMgmtNodeInstance _nodeInstance, PrintMgmtDocumentType _docType)
{
    // added the new swith condition for the report node.

        case PrintMgmtNodeType::InternalDeliveryNote:
            // When no parent is present, return null
            result.parmReferencedTableBuffer(null);
            result.parmNodeDefinition(PrintMgmtNode::construct(PrintMgmtNodeType::InternalDeliveryNote));
            break;
     
    return result;
}

Class –PrintMgmtNode
Method-Construct

public static PrintMgmtNode construct(PrintMgmtNodeType _nodeType)
{
    ;
// add the node to construct the report in which module

    switch (_nodeType)
    {
     
        case PrintMgmtNodeType::InternalDeliveryNote:
            return PrintMgmtNode_Invent::construct();
       
    }

    return null;
}


Class –PrintMgmtDocType
Method-getQueryTableID,getDefaultReportFormat

public int getQueryTableId()
{
    int tableId;

// added switch condition for getting the table id.
    switch (docType)
    {
      
        
        case PrintMgmtDocumentType::InternalDeliveryNote:
            tableId = tableNum(WMSJournalTable);
            break;
     

    }

    return tableId;
}

public PrintMgmtReportFormatName getDefaultReportFormat()
{
    switch (docType)
    {
       
        case PrintMgmtDocumentType::InternalDeliveryNote:
            return ssrsReportStr(InternalDeliveryNote, Report);

    }

    throw Exception::Internal;
}

Class-PrintMgmtNode_Invent
Method-getDocumentTypes

This method will load the print management element in the print management setup.
public List getDocumentTypes()
{
    List docTypes;
    ;

    docTypes = new List(Types::Enum);

    if (isConfigurationkeyEnabled(configurationKeyNum(LogisticsBasic)))
    {
        docTypes.addEnd(PrintMgmtDocumentType::InventPickList);

     
        docTypes.addEnd(PrintMgmtDocumentType::InternalDeliveryNote);
     
    }
    return docTypes;
}


Execute the Report using printmanagement setup we have to write the class which inherits SRSPrintMgmtController
So Our class declarations will be look like this
class InternalDeliveryNoteController extends SrsPrintMgmtController
{
    #define.ReportName('InternalDeliveryNote.Report')
    InventDimParm                               inventDimVisible;
    WMSPickingRoute                             wmsPickingRoute;
    PrintCopyOriginal                           printCopyOriginal;
    WMSJournalTable                             wmsJournalTable;
    WMSJournalTrans                             wmsJournalTrans;
}

public static void main(Args _args)
{
    InternalDeliveryNoteController controller = new InternalDeliveryNoteController();
    controller.parmReportName(#ReportName);
    controller.parmArgs(_args);
    controller.parmDialogCaption(_args.parmEnum() == PrintCopyOriginal::Original ? "Internal Delivery Note" : strFmt("%1 - %2","Original", "Copy"));
    controller.parmPrintType(_args.parmEnum());
    controller.parmShowDialog(false);


    controller.startOperation();
}

protected void setRanges(Query _query)
{
    QueryBuildRange         queryBuildRange;
    FormDataSource          formDataSource;
    Common                  common;
    Range                   journalRange, lineRange;

    if (!this.parmArgs().record().RecId)
    {
        throw error(strFmt("@SYS22338",funcName()));
    }

    if (this.parmArgs().dataset() == tableNum(WMSJournalTable) || this.parmArgs().dataset() == tableNum(WMSJournalTrans))
    {
        if (_query)
        {
            formDataSource  = this.parmArgs().record().dataSource();

            if(formDataSource && formDataSource.anyMarked())
            {
                common          = formDataSource.getFirst(1);

                while(common.RecId)
                {
                    if (common.TableId == tableNum(WMSJournalTable))
                    {
                        journalRange    += common.(fieldNum(WMSJournalTable, JournalId)) + ",";
                        wmsJournalTable=common;
                    }
                    else
                    {
                        journalRange    = common.(fieldNum(WMSJournalTrans, JournalId)) + ",";
                        lineRange       += strFmt("%1,", common.(fieldNum(WMSJournalTrans, LineNum)));
                        WMSJournalTrans=common;
                    }

                    common          = formDataSource.getNext();
                }
            }
            else
            {
                common          = this.parmArgs().record();

                if (common.TableId == tableNum(WMSJournalTable))
                {
                    journalRange    = common.(fieldNum(WMSJournalTable, JournalId));
                        wmsJournalTable=common;
                }
                else
                {
                    journalRange    = common.(fieldNum(WMSJournalTrans, JournalId));
                    lineRange       = strFmt("%1,", common.(fieldNum(WMSJournalTrans, LineNum)));
                    WMSJournalTrans=common;
                }
            }

            queryBuildRange = SysQuery::findOrCreateRange(_query.dataSourceTable(tableNum(WMSJournalTrans)), fieldNum(WMSJournalTrans, JournalId));
            queryBuildRange.value(journalRange);

            if (lineRange)
            {
                queryBuildRange = SysQuery::findOrCreateRange(_query.dataSourceTable(tableNum(WMSJournalTrans)), fieldNum(WMSJournalTrans , LineNum));
                queryBuildRange.value(lineRange);
            }
            else
                _query.dataSourceTable(tableNum(WMSJournalTrans)).clearRange(fieldNum(WMSJournalTrans , LineNum));
        }
    }
    else
    {
        throw error(strFmt("@SYS23396",funcName()));
    }

}

Override the method which sets our ranges for query  to the report

protected void prePromptModifyContract()
{
    this.setRanges(this.parmReportContract().parmQueryContracts().lookup(this.getFirstQueryContractKey()));
}

public PrintCopyOriginal parmPrintType(PrintCopyOriginal _parmPrintType = PrintCopyOriginal)
{
    PrintCopyOriginal = _parmPrintType;
    return PrintCopyOriginal;
}

public SRSPrintDestinationSettings parmDefaultCopyPrintJobSettings(SRSPrintDestinationSettings _printSettings = printMgmtReportRun.parmDefaultCopyPrintJobSettings())
{
    return printMgmtReportRun.parmDefaultCopyPrintJobSettings(_printSettings);
}

public SRSPrintDestinationSettings parmDefaultOriginalPrintJobSettings(SRSPrintDestinationSettings _printSettings= printMgmtReportRun.parmDefaultOriginalPrintJobSettings())
{
    return printMgmtReportRun.parmDefaultOriginalPrintJobSettings(_printSettings);
}

public void loadPrintSettings(Common _jourTable, Common _transTable, str _languageId, str _documentKeyValue = '')
{
    boolean isValidReference(Common _referencedTableBuffer)
    {
        PrintMgmtNodeInstance nodeInstance = new PrintMgmtNodeInstance();

        nodeInstance.parmNodeDefinition(PrintMgmtNode::construct(PrintMgmtNodeType::InternalDeliveryNote));
        nodeInstance.parmReferencedTableBuffer(_referencedTableBuffer);

        return nodeInstance.isValidReference();
    }

    void setSettingDetail(PrintMgmtDocInstanceType _type, SRSPrintDestinationSettings _defaultSettings)
    {
        PrintMgmtPrintSettingDetail printSettingDetail = new PrintMgmtPrintSettingDetail();

        printSettingDetail.parmReportFormatName(PrintMgmtReportFormat::findSystem(PrintMgmtDocumentType::InternalDeliveryNote).Name);

        printSettingDetail.parmType(_type);

        printSettingDetail.parmInstanceName(enum2str(_type));

        // Since this will be reported to the screen, one copy is the only thing that makes sense
       // printSettingDetail.parmNumberOfCopies(1);

        printSettingDetail.parmPrintJobSettings(_defaultSettings);
        printSettingDetail.parmNumberOfCopies(_defaultSettings.numberOfCopies());
        printMgmtReportRun.loadSettingDetail(printSettingDetail, _documentKeyValue);
    }

    if (this.parmPrintType() == PrintCopyOriginal::OriginalPrint && isValidReference(_transTable))
    {
        // Print an original
        printMgmtReportRun.load(_jourTable, _transTable, _languageId, _documentKeyValue);
    }
    else if (this.parmPrintType() == PrintCopyOriginal::Copy)
    {
        // Print a copy
        setSettingDetail(PrintMgmtDocInstanceType::Copy, this.parmDefaultCopyPrintJobSettings());
    }
    else
    {
        // Print an original.  We also default to print one original when we are trying to
        // print using Print Mgmt information, but don't have a valid table reference.
        // This covers the reprint case where the original transaction record may not be present.
        setSettingDetail(PrintMgmtDocInstanceType::Original, this.parmDefaultOriginalPrintJobSettings());
    }

    if (!printMgmtReportRun.more())
    {
        checkFailed("@SYS78951");
    }
}


This method is used to get the printmgmt settings from the table printmgmtsettings that we define in the pringmangement setup.

private void getPrintSettings(PrintMgmtDocInstanceType _printMgmtDocInstanceType =PrintMgmtDocInstanceType::Copy)
{
    PrintMgmtSettings  printMgmtSettings;
    PrintMgmtDocInstance printMgmtDocInstance;
    PrintMgmtReportFormat printMgmtReportFormat;
    SRSPrintDestinationSettings srsPrintDestinationSettings;

    select RecId from printMgmtReportFormat where printMgmtReportFormat.Name==this.parmReportName()
    join DocumentType,PrintType from printMgmtDocInstance where printMgmtDocInstance.DocumentType==PrintMgmtDocumentType::InternalDeliveryNote
        && printMgmtDocInstance.PrintType==_printMgmtDocInstanceType
    Join PrintJobSettings,NumberOfCopies,ParentId from printMgmtSettings where printMgmtSettings.ReportFormat==printMgmtReportFormat.RecId
    && printMgmtSettings.ParentId==printMgmtDocInstance.RecId;

    if(_printMgmtDocInstanceType==PrintMgmtDocInstanceType::Copy)
    {
        srsPrintDestinationSettings=new SRSPrintDestinationSettings(printMgmtSettings.PrintJobSettings);
        srsPrintDestinationSettings.numberOfCopies(printMgmtSettings.NumberOfCopies);
        this.parmDefaultCopyPrintJobSettings(srsPrintDestinationSettings);
    }
    else
    {
        srsPrintDestinationSettings=new SRSPrintDestinationSettings(printMgmtSettings.PrintJobSettings);
        srsPrintDestinationSettings.numberOfCopies(printMgmtSettings.NumberOfCopies);
        this.parmDefaultOriginalPrintJobSettings(srsPrintDestinationSettings);
    }
}


Override the runprintmgmt function to call the report with the settings that we used in the above functions.
protected void runPrintMgmt()
{
    printMgmtReportRun=PrintMgmtReportRun::construct(PrintMgmtHierarchyType::Invent,PrintMgmtNodeType::InternalDeliveryNote,PrintMgmtDocumentType::InternalDeliveryNote);
    printMgmtReportRun.parmReportRunController(this);

    if (this.parmPrintType() == PrintCopyOriginal::Copy)
    {
        //// Print a copy
        this.getPrintSettings();
    }
    else
    {
        //// Print an original.  We also default to print one original when we are trying to
        //// print using Print Mgmt information, but don't have a valid table reference.
        //// This covers the reprint case where the original transaction record may not be present.
        this.getPrintSettings(PrintMgmtDocInstanceType::Original);
        //printMgmtReportRun.loadSettingDetail(this.setSettingDetail(PrintMgmtDocInstanceType::Original, printMgmtReportRun.parmDefaultOriginalPrintJobSettings()));
    }

    this.loadPrintSettings(wmsJournalTable,wmsJournalTrans,CompanyInfo::languageId());
    this.outputReports();
}

After finishing the development we have to set the values for the printmanagement.
Goto- inventorymanagement parameters-Printmanagement-click on printmanagement button.
Then the printmgmtuiMain form will loads with the nodes that we define in the development. As follows.

Then click on internaldelivery note and right click you will get new and click ok.it will create original, create again new it will create copy for that document as follows

and click on close button.Create one menuitem  for output section as follows.

6 comments:

  1. Hi you have not talked about the last step "print management setup" - report format setup?

    ReplyDelete
  2. How does print management work when you want to mix output? Take for example a customer collection note SSRS report, can the print management be used within the standard controller/contract/DP classes if i wanted to email record if customer has an email and print if customer does not have an email. I fprinting 1 customer then the print management works fine but if RDP then can you set print management with each?

    ReplyDelete
  3. Hi Krishna

    I have a report which i print by providing some values to parameters. Also i need to save the report as pdf through a batch class. In Batch class i am trying to call the report controller class. But i was unable to execute the controller class and run the process.

    Can you please help me in this

    ReplyDelete
    Replies
    1. I think if we are calling the run method of controller class it executes. Any how can you share any knowledge regarding this type of functionality (like if we want to pass parameters before saving the file)

      Thanks
      Gangadhar

      Delete
  4. Thank you very much for this tutorial!

    ReplyDelete
  5. Useful information shared. I am very much pleased to get helpful information from here.. Thanks for giving us nice info. Fantastic walk through. I appreciate this post.

    ReplyDelete

Thanks for visiting my blog,
I will reply for your comment within 48 hours.

Thanks,
krishna.