30 Ocak 2019 Çarşamba

AX - 2012 Satınalma sipariş raporunu direk email olarak göndermek

Satınlama sipariş raporunu (PurchPurchaseOrder) direk mail olarak göndermek:

    SrsReportRunController          controller = new SrsReportRunController();
    PurchPurchaseOrderContract      Contract = new PurchPurchaseOrderContract();
    SRSPrintDestinationSettings     printSettings;
    VendPurchOrderJour              orderJour;
    SrsReportEMailDataContract      emailContract = new SrsReportEMailDataContract();

   select firstonly orderJour
            order by PurchOrderDate Desc,CreatedDateTime Desc
            where orderJour.PurchId == "ST000181";

    emailContract.parmAttachmentFileFormat(SRSReportFileFormat::PDF);
    emailContract.parmSubject("Purchase Order");
    emailContract.parmTo("test@hotmail.com");
    
    
    controller.parmReportName(ssrsReportStr(PurchPurchaseOrder, Report));
    controller.parmShowDialog(false);
    Contract.parmRecordId(orderJour.RecId);
    controller.parmReportContract().parmRdpContract(Contract);

    printSettings = controller.parmReportContract().parmPrintSettings();
    printSettings.printMediumType(SRSPrintMediumType::Email);
    printSettings.fileFormat(SRSReportFileFormat::PDF);
    printSettings.parmEMailContract(emailContract);
    printSettings.overwriteFile(true);

    controller.runReport();


Yukarıdaki yöntemde sistem AX mail göndericisi yerine Outlook'u kullanmak isteyecektir. Aşağıdaki yöntem alternatif olabilir. Yukarıdaki yöntemin dezavantajı Outlook'u kullanması iken aşağıdakinin de dezavantajı dosyayı öncelikle diskte bir yere yazmanızın gerekmesi:


  PurchTable          purchTable;
    str                 body;
    PurchLine           purchLine;
    boolean             found;
    VendPurchOrderJour  orderJour;
    Filename            filename;
    SysMailer           mailer;
    SysEmailParameters  parameters;
      SrsReportRunController  controller = new SrsReportRunController();
    PurchPurchaseOrderContract  contract = new PurchPurchaseOrderContract();
 SRSPrintDestinationSettings printSettings;   
    
    controller.parmReportName(ssrsReportStr(PurchPurchaseOrder,Report));
    controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);
printSettings = controller.parmReportContract().parmPrintSettings();
printSettings.fileFormat(SRSReportFileFormat::PDF);
printSettings.printMediumType(SRSPrintMediumType::File);
printSettings.overwriteFile(true);

printSettings.fileName(@filename);
filename = strFmt(@"%1%2.PDF",WinAPI::getTempPath(),"PO00001");

     select firstonly orderJour
            order by PurchOrderDate Desc,CreatedDateTime Desc
            where orderJour.PurchId == "PO00001"
    contract.parmRecordId(orderJour.RecId);
    controller.parmReportContract().parmRdpContract(contract);
    
    controller.parmShowDialog(false);
    controller.runReport();
    infolog.clear();
    
    new InteropPermission(InteropKind::ComInterop).assert();
    mailer = new SysMailer();
    parameters = SysEmailParameters::find();


    if (parameters.SMTPRelayServerName)
    {
        mailer.SMTPRelayServer(parameters.SMTPRelayServerName,
                            parameters.SMTPPortNumber,
                            parameters.SMTPUserName,
                            SysEmailParameters::password(),
                            parameters.NTLM);
    }
    else
    {
        mailer.SMTPRelayServer(parameters.SMTPServerIPAddress,
                            parameters.SMTPPortNumber,
                            parameters.SMTPUserName,
                            SysEmailParameters::password(),
                            parameters.NTLM);
    }
    body = '<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-9">';    
    body += strFmt(@"<br><caption>%1</caption><br><br>","Satınalma sipariş formunuz ektedir.");      
    
    mailer.fromAddress("sender@hotmail.com");
    mailer.tos().appendAddress("test@hotmail.com");
    mailer.htmlBody(body);
    mailer.subject(title);
    mailer.attachments().add(filename);
    mailer.bodyCharSet("Windows-1254");
    mailer.sendMail();

Hiç yorum yok:

Yorum Gönderme