Tuesday, 17 March 2015

Printmanagement - Job

static void CIT_PrintLabelUpdate(Args _args)
{
    PrintMgmtDocInstance                printMgmtDocInstance;
    PrintMgmtSettings                   printMgmtSetting ;
    SRSPrintDestinationSettings         srsPrintSettings = new SRSPrintDestinationSettings();
    CustTable                           custTable;

    ttsBegin;

    while select printMgmtDocInstance
        where PrintMgmtDocInstance.ReferencedTableId == 77
           //&& PrintMgmtDocInstance.DocumentType      == PrintMgmtDocumentType::SalesOrderInvoice
           //&& PrintMgmtDocInstance.DocumentType      == PrintMgmtDocumentType::SalesOrderConfirmation
           && PrintMgmtDocInstance.DocumentType      == PrintMgmtDocumentType::Quotation
   {
        printMgmtSetting = PrintMgmtSettings::find(printMgmtDocInstance.RecId,1,true);

        if (printMgmtSetting.RecId)
        {
            srsPrintSettings.unpack(printMgmtSetting.PrintJobSettings);
            if (srsPrintSettings.printMediumType() == SRSPrintMediumType::Email)
            {
                custTable = CustTable::findRecId(printMgmtDocInstance.ReferencedRecId);

                //info(strFmt("Value: %1",CustTable::findRecId(printMgmtDocInstance.ReferencedRecId).AccountNum));
                //info(srsPrintSettings.emailTo());
                //info(srsPrintSettings.emailSubject());

                if (custTable.languageId() == 'nb-no')
                {
                    //srsPrintSettings.emailSubject("Faktura fra Molde Jarnvareforretning AS");
                    //srsPrintSettings.emailSubject("Ordrebekreftelse fra Molde Jarnvareforretning AS");
                    srsPrintSettings.emailSubject("Tilbud fra Molde Jarnvareforretning AS");
                }
                else
                {
                    info(strFmt("Value: %1",CustTable::findRecId(printMgmtDocInstance.ReferencedRecId).AccountNum));
                    info(srsPrintSettings.emailTo());
                    info(srsPrintSettings.emailSubject());


                    //srsPrintSettings.emailSubject("Invoice from Molde Jarnvareforretning AS");
                    //srsPrintSettings.emailSubject("Order confirmation from Molde Jarnvareforretning AS");
                    srsPrintSettings.emailSubject("Offer from Molde Jarnvareforretning AS");

                    info(srsPrintSettings.emailSubject());
                    info('-------------------------');
                }

                //printMgmtSetting.PrintJobSettings = srsPrintSettings.pack();
                //printMgmtSetting.doUpdate();

                //info(srsPrintSettings.emailSubject());
                //info('-------------------------');
            }
        }
    }

    ttsCommit;
}
===================================================================
 https://community.dynamics.com/ax/f/33/t/127517.aspx

static void OverridePrintMangement(Args _args)
{
PrintMgmtDocInstance printMgmtDocInstance;
PrintMgmtSettings printMgmtSettings;
PrintMgmtReportFormat printMgmtreportFormat;
    CustTable   custtbl;
// other
container printerSetting = conNull();
SRSPrintDestinationSettings printDestinationSetting = new SRSPrintDestinationSettings();
// Populate/Create TargetBuffer(s)
printMgmtDocInstance.DocumentType = PrintMgmtDocumentType::SalesOrderConfirmation;
//printMgmtDocInstance.Name = printMgmtDocInstance_Name;
printMgmtDocInstance.NodeType = PrintMgmtNodeType::CustTable;
printMgmtDocInstance.PrintType = PrintMgmtDocInstanceType::Original;
printMgmtDocInstance.PriorityId = 1;
printMgmtDocInstance.ReferencedRecId = 22565434386;  //Recid of Customer
printMgmtDocInstance.ReferencedTableId = 77; //Table Id of custtable
printMgmtDocInstance.insert();
// just use a new instance of SRSPrintDestinationSettings to serialize an empty container
printDestinationSetting.unpack(printerSetting);
printDestinationSetting.printMediumType(SRSPrintMediumType::Screen);
   
    select * from custtbl where custtbl.RecId   ==  22565434386;
printDestinationSetting.emailTo(custtbl.email());
//printDestinationSetting.emailCc(ccEmailString);
//printDestinationSetting.printerName(printerName);
printerSetting = printDestinationSetting.pack();

printMgmtSettings.clear();
printMgmtSettings.Description = printmgmtdocInstance.Name;
printMgmtSettings.NumberOfCopies = 1;
printMgmtSettings.ParentId = printmgmtdocInstance.RecId;
printMgmtSettings.PrintJobSettings = printerSetting;
printMgmtSettings.PriorityId = printMgmtDocInstance.PriorityId;
printMgmtSettings.ReportFormat = printmgmtreportFormat.RecId;
printMgmtSettings.insert();
    info("job is executed");
}

 

No comments:

Post a Comment