最新消息:ww12345678 的部落格重装上线,希望大家继续支持。

在X ++中创建打印管理设置 / Create print management settings in X++

网络文摘 William 21浏览 0评论

Purpose:

The purpose of this blog post is to demonstrate how can we create print management settings in X++

Product:

Dynamics AX 2012

Description:

The code creates a print management settings record on a customer for collection letter note document and uses first contact of type email and purpose “Collection” found on the customer record to create print destination settings.

Code:

static void MAKCustPrintMgmtSettings(Args _args)
{
    PrintMgmtSettings              printMgtSettings;
    PrintMgmtDocInstance           printMgtDocInstance;
    SRSPrintDestinationSettings    printDestinationSettings;
    PrintMgmtReportFormat          PrintMgmtReportFormat;
    PrintMgmtDocumentType          PrintMgmtDocumentType;
    PrintMgmtDocInstanceType       PrintMgmtDocInstanceType;
    NoYes                          NoYes;
    SRSReportFileFormat            SRSReportFileFormat;
    SRSPrintMediumType             SRSPrintMediumType;
    str                            EmailTo;
    CustTable                      custTable;
    LogisticsElectronicAddress     electronicAddress;
    LogisticsElectronicAddressRole electronicAddrRole;
    LogisticsLocationRole          locationRole;
    container                      record;
    int                            totalRecords = 0;
    container                      printerSetting = conNull();

    try
    {
        while select custTable where custTable.AccountNum == 'C000115'
        {
            select firstOnly electronicAddress
                where electronicAddress.Location == DirPartyLocation::findOrCreate(custTable.Party, 0).Location
                    && electronicAddress.Type == LogisticsElectronicAddressMethodType::Email
                join electronicAddrRole
                    where electronicAddrRole.ElectronicAddress == electronicAddress.RecId
                join locationRole
                    where locationRole.RecId == electronicAddrRole.LocationRole
                        && locationRole.Name == "Collection";

            if (electronicAddress.RecId)
            {
                EmailTo = electronicAddress.Locator;
            }

            printDestinationSettings = new SRSPrintDestinationSettings(printerSetting);
            printDestinationSettings.unpack(printerSetting);
            printDestinationSettings.caption("@SYS131685");
            printDestinationSettings.emailTo(EmailTo);
            printDestinationSettings.printMediumType(SRSPrintMediumType::Email);
            printDestinationSettings.emailSubject('Collection Letter');
            printDestinationSettings.emailAttachmentFileFormat(SRSReportFileFormat::PDF);
            printDestinationSettings.numberOfCopies(1);
            printMgtDocInstance = PrintMgmtDocInstance::find(custTable.RecId, custTable.TableId, PrintMgmtNodeType::CustTable, PrintMgmtDocumentType::CustCollectionLetter, 1);

            ttsBegin;

            if (printMgtDocInstance)
            {
                printMgtDocInstance.selectForUpdate(true);
            }

            printMgtDocInstance.Name              = ""; // To override give a blank value
            printMgtDocInstance.DocumentType      = PrintMgmtDocumentType::CustCollectionLetter;
            printMgtDocInstance.PrintType         = PrintMgmtDocInstanceType::Original;
            printMgtDocInstance.PriorityId        = 1;
            printMgtDocInstance.Suppress          = NoYes::No;
            printMgtDocInstance.ReferencedTableId = custTable.TableId;
            printMgtDocInstance.ReferencedRecId   = custTable.RecId;
            printMgtDocInstance.NodeType          = PrintMgmtNodeType::CustTable;

            if (printMgtDocInstance)
            {
                printMgtDocInstance.update();
            }
            else
            {
                printMgtDocInstance.insert();
            }

            select firstOnly printMgtSettings
                order by PriorityID
                where printMgtSettings.ParentId==printMgtDocInstance.RecId
                    && printMgtSettings.PriorityID == 1;

            if (printMgtSettings)
            {
                printMgtSettings.selectForUpdate(true);
            }

            printMgtSettings.ParentId           = printMgtDocInstance.RecId;
            printMgtSettings.ReportFormat       = PrintMgmtReportFormat::findByType(PrintMgmtDocumentType::CustCollectionLetter, 'CustCollectionJour.Report', '').RecId;
            printMgtSettings.PrintJobSettings   = printDestinationSettings.pack();
            printMgtSettings.NumberOfCopies     = 1;
            printMgtSettings.PriorityId         = 1;

            if (printMgtSettings)
            {
                printMgtSettings.update();
            }
            else
            {
                printMgtSettings.insert();
            }
            ttsCommit;

            totalRecords++;

            if (printMgtDocInstance && printMgtSettings)
            {
                info(strFmt("Customer %1 updated successfully", custTable.AccountNum));
            }
            else
            {
                error(strFmt("Failed to update customer %1", custTable.AccountNum));
            }
        }
    }
    catch (Exception::Error)
    {
        throw(Exception::Error);
    }

    info(strFmt("Total records read = %1", totalRecords));
}
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址