Translate

Wednesday, January 15, 2020

X++ code to Export emails under print management destination settings

printMgmtSettings           printMgmtSettings;
    container                   printerSetting;
    SRSPrintDestinationSettings printDestinationSetting;
    PrintMgmtDocInstance        printMgmtDocInstance;
    while select printMgmtSettings
    {
        printDestinationSetting = new SRSPrintDestinationSettings();
        printDestinationSetting.unpack(printMgmtSettings.PrintJobSettings);
       
        if(printDestinationSetting.printMediumType() == srsPrintMediumType::Email)
        {
            select * from printMgmtDocInstance where printMgmtDocInstance.RecId==printMgmtSettings.ParentId;
            info(strFmt("%1 -%2",printMgmtDocInstance.NodeType, printDestinationSetting.emailTo()));
        }
    }

X++ code to setup print management destination settings on Customer

 PrintMgmtSettings       printMgmtSettings;
    PrintMgmtDocInstance    printMgmtDocInstance;
    CustTable               custtable = CustTable::find("C005751");

    container               printerSetting;
    SRSPrintDestinationSettings printDestinationSetting;

    printMgmtDocInstance    = printMgmtDocInstance::find(custtable.RecId,77,printMgmtNodeType::CustTable,printMgmtDocumentType::CustAccountStatement,1);

    if(printMgmtDocInstance.RecId == 0 && custtable.email() != strMin())
    {
        printerSetting = conNull();
        printDestinationSetting = new SRSPrintDestinationSettings();

        ttsBegin;

        printMgmtDocInstance.DocumentType = printMgmtDocumentType::CustAccountStatement;
        //printMgmtDocInstance.Name = strFmt("Email 'Account Statements' to %1", custtable.AccountNum);
        printMgmtDocInstance.NodeType = printMgmtNodeType::CustTable;
        printMgmtDocInstance.PrintType = PrintMgmtDocInstancetype::Original;
        printMgmtDocInstance.PriorityId = 1;
        printMgmtDocInstance.ReferencedRecId = custtable.recId;
        printMgmtDocInstance.ReferencedTableId = 77;// CustTable;
        printMgmtDocInstance.insert();

        // just use a new instance of SRSPrintDestinationSettings to serialize an empty container
        printDestinationSetting.unpack(printerSetting);
        printDestinationSetting.printMediumType(srsPrintMediumType::Email);
        printDestinationSetting.emailTo(custtable.email());
        //printDestinationSetting.emailCc(ccEmailString);
        printDestinationSetting.emailSubject("Proserv statements");
        printDestinationSetting.emailAttachmentFileFormat(SRSReportFileFormat::PDF);
        printerSetting = printDestinationSetting.pack();


        printMgmtSettings.clear();
        printMgmtSettings.Description = printmgmtdocInstance.Name;
        printMgmtSettings.NumberOfCopies = 1;
        printMgmtSettings.ParentId = printmgmtdocInstance.RecId;
        printMgmtSettings.PrintJobSettings = printerSetting;
        printMgmtSettings.PriorityId = printMgmtDocInstance.PriorityId;
        printMgmtSettings.insert();

        ttsCommit;
    }