Tuesday, 31 March 2015

Mailing PO confirmation report in Ax 2012

PO confirmation report has to be sent mail once gets confirmed.
Default standard Ax will print the report using PurchPurchOrderJournalPrint,
to mail the report, the code has to written in the PurchPurchOrderJournalPrint,doPrint() method
as below
/// <summary>
/// Prints the document.
/// </summary>
protected void doPrint()
{
    this.printConfirmReport();
    this.sendmail(vendPurchOrderJour);

    vendPurchOrderJour.printJournal(this, journalList);
}

private void printConfirmReport()
{
    Args                        parameters = new Args();
    SRSPrintDestinationSettings printSettings;
    SrsReportRunController      controller = new SrsReportRunController();
    PurchPurchaseOrderContract  contract = new PurchPurchaseOrderContract();
    FILENAME                    filename;
    boolean                     newLine;
    Name                        filenamepath;
    ;
    newLine = journalList.first(vendPurchOrderJour);
    parameters.caller(this);
    if (journalList)
    {
        parameters.object(journalList);
    }
    controller.parmReportName(ssrsReportStr(PurchPurchaseOrder, Report));
    contract.parmRecordId(vendPurchOrderJour.RecId);
    contract.parmDocumentTitle("@SYS25545");
    controller.parmReportContract().parmRdpContract(contract);
    controller.parmShowDialog(false);
    printSettings = controller.parmReportContract().parmPrintSettings();
    printSettings.printMediumType(SRSPrintMediumType::File);
    printSettings.fileFormat(SRSReportFileFormat::PDF);
    printSettings.overwriteFile(true); 
    filenamepath = PurchParameters::find().PurchConfirmationFilepath;   
    filename = filenamepath + curext() + '_' +vendPurchOrderJour.PurchOrderDocNum + '.PDF';   
    printSettings.fileName(filename);
    controller.parmArgs(parameters);
    controller.startOperation();
}
private void IMX_sendmail(VendPurchOrderJour _vendPurchOrderJour)
{

SysMailer           mailer = new SysMailer();
SysEmailParameters  parameters = SysEmailParameters::find();
FilePath            filePath;
HcmWorker           hcmWorker;
PurchTable          purchTable;
Name                filename;
;
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);
}
filename = PurchParameters::find().PurchConfirmationFilepath;
purchTable  = PurchTable::find(_vendPurchOrderJour.PurchId);
hcmWorker   = HcmWorker::find(purchTable.Requester);
mailer.subject(_vendPurchOrderJour.PurchId);
mailer.fromAddress(DirPartyTable::findByName(UserInfoHelp::userName(curUserId())).primaryEmail());
mailer.htmlBody('Purchase Order confirmation of ' + _vendPurchOrderJour.PurchId +'.' + 'Please Find the Attachment.');
mailer.tos().appendAddress(hcmWorker.email());
mailer.tos().appendAddress(VendTable::find(purchTable.OrderAccount).email());
filePath = filename + curext() + '_' +vendPurchOrderJour.PurchOrderDocNum + '.PDF';
mailer.attachments().add(filePath);
mailer.sendMail();
CodeAccessPermission::revertAssert();
}

Correct me if am wrong....

No comments:

Post a Comment

Best Practices for Troubleshooting Application Issues in D365 and Power Platform

When facing application issues, it’s important to systematically troubleshoot before reaching out for support.  Follow these steps to ensure...