Monday, August 24, 2009

Add new print management option in Ax 2009

To add new print management option "Picking list label" in AR->setup-> Forms->form setup -> print management

  1. Base enum: PrintMgmtDocumentType
    Add new element InventPickListLabel, label "Picking list label"

  2. Class: PrintMgmtNode_Invent
    method(): getDocumentTypes
    Add the following code after the docTypes.addEnd(PrintMgmtDocumentType::InventPickList);
    docTypes.addEnd(PrintMgmtDocumentType::InventPickListLabel);

  3. Class: PrintMgmtDocType
    method: getQueryTableId(), getQueryRangeFields()
    Add Case: PrintMgmtDocumentType::InventPickListLabel to existing case
    PrintMgmtDocumentType::InventPickList.

  4. Form CustFormletterParameters -> PrintMgmt button clicked
    \Forms\CustFormletterParameters\Designs\Design\[Tab:Tab]\[TabPage:General]\[Group:ButtonGroup]\Button:PrintMgmt\Methods\clicked
    element.createPickingLabelPrintMgmtDocInstance(); [after the super. Refer below for the method]
    Add this after the inventDocs.addEnd for InventPickList
    inventDocs.addEnd(PrintMgmtDocumentType::InventPickListLabel);

  5. Create the following method in the form CustFormletterParameters
    void createPickingLabelPrintMgmtDocInstance()
    {
    PrintMgmtDocInstance printMgmtDocInstance;
    RecId recId = 0;
    tableId tableId = 0;
    ;
    if (PrintMgmtDocInstance::exist(recId,tableId,PrintMgmtNodeType::Invent,PrintMgmtDocumentType::InventPickListLabel,1) )
    return;
    ttsbegin;
    printMgmtDocInstance.selectForUpdate(true);
    printMgmtDocInstance.clear();
    printMgmtDocInstance.PrintType = PrintMgmtDocInstanceType::Original;
    printMgmtDocInstance.Name = "";
    printMgmtDocInstance.PriorityId = 1;
    printMgmtDocInstance.DocumentType = PrintMgmtDocumentType::InventPickListLabel;
    printMgmtDocInstance.ReferencedRecId = recId;
    printMgmtDocInstance.ReferencedTableId = tableId;
    printMgmtDocInstance.NodeType = PrintMgmtNodeType::Invent;
    printMgmtDocInstance.Suppress = NoYes::No;
    printMgmtDocInstance.insert();

    printMgmtDocInstance.selectForUpdate(true);
    printMgmtDocInstance.clear();
    printMgmtDocInstance.PrintType = PrintMgmtDocInstanceType::Copy;
    printMgmtDocInstance.Name = "@SYS92837";
    printMgmtDocInstance.PriorityId = 2;
    printMgmtDocInstance.DocumentType = PrintMgmtDocumentType::InventPickListLabel;
    printMgmtDocInstance.ReferencedRecId = recId;
    printMgmtDocInstance.ReferencedTableId = tableId;
    printMgmtDocInstance.NodeType = PrintMgmtNodeType::Invent;
    printMgmtDocInstance.Suppress = NoYes::No;
    printMgmtDocInstance.insert();
    ttscommit;
    }


  6. Class: SalesFormLetterReport_PickingListLabel()
    Create a new class which is duplicate of SalesFormLetterReport_PickingList();
    modify the method getPrintMgmtDocumentType() to return InventPickListLabel
    modify the method getPrintMgmtNodeType to return only PrintMgmtNodeType::Invent;
  7. Class: FormLetterReport
    method: construct()
    Add the following case;
    case PrintMgmtDocumentType::InventPickListLabel:
    return new SalesFormLetterReport_PickingListLabel();

  8. Add the code to call the new print management settings in the report.
    Ex: WMSPickingList_OrderPick Report: Init method
    use salesFormLetterReport = FormLetterReport::construct(PrintMgmtDocumentType::InventPickListLabel)
    instead of salesFormLetterReport = FormLetterReport::construct(PrintMgmtDocumentType::InventPickList)
    Add the following lines after super()
    printCopyOriginal = PrintCopyOriginal::OriginalPrint;
    this.report().interactive(false);
    hideDialog = true;

    salesFormLetterReport = FormLetterReport::construct(PrintMgmtDocumentType::InventPickListLabel);
    salesFormLetterReport.parmReportDesign(element);
    salesFormLetterReport.parmPrintType(printCopyOriginal);
    salesFormLetterReport.parmUsePrintMgmtDestinations(true);
    hidePrinterSelect = true;

    add the following code in the fetch method
    Common referencedTable;

    referencedTable = null;
    salesFormLetterReport.loadPrintSettings(
    wmsPickingRoute,
    referencedTable,
    CompanyInfo::find().LanguageId);

    while (salesFormLetterReport.moveNextPrintSetting())
    {
    // Set report print settings
    element.unpackPrintJobSettings(salesFormLetterReport.getCurrentPrintSetting().parmPrintJobSettings().packPrintJobSettings());
    element.printJobSettings().copies(salesFormLetterReport.getCurrentPrintSetting().parmNumberOfCopies());

    //relevant send methods
    }