email should trigger while posting Invoice with details

Hi Experts ,

I have one requirement while doing Invoice in the >>AP>> Purchase Order details>> i am taking One purchase Order (status = completed ) >> Posting >> it will open Posting Invoice Form >> we are giving Invoice Number (INV001) .

when the "Ok "button clicked Mail should be trigger with Details of Invoice Number , Invoice date , Invoice Amount

please help where should write the code ? and where i need to start the coding ?

I used Below Code for Vendor payment

static void sendEmail(container con ) //LedgerJournalTrans parmLedgerJournalTrans)
{
SysMailer mailer = new SysMailer();
SysEmailParameters parameters = SysEmailParameters::find();
str emailFrom = sysuserInfo::find(curUserId(),false).Email;
InteropPermission permission = new InteropPermission(InteropKind::ComInterop);
str _emailTo;
str _subject;
str _bodyText;
int i;
LedgerJournalTrans parmLedgerJournalTrans,ledgerJournalTrans;
VendinvoiceJour vendInvoiceJour;
VendTrans vendTrans;
str _invoice;
str _invoiceamt;
str _invoiceDate;

Recid recid;
;
for(i =1 ; i <= conlen(con); i++)
{
_invoice = “”;
_invoiceamt = “”;
_invoiceDate ="";
recid = conpeek(con, i);
select firstonly * from parmLedgerJournalTrans
where parmLedgerJournalTrans.RecId == recid;

if (parmLedgerJournalTrans.Invoice)
{
_emailTo = vendtable::find(parmLedgerJournalTrans.AccountNum).Email;
_subject = “Payment Notification “;
_bodyText= “Following payment is credited to your account : " + " Invoice Number : " +strfmt(”%1”,parmLedgerJournalTrans.Invoice)+”, “+
" Invoice Date : " + strfmt(”%1",parmLedgerJournalTrans.TransDate) +", “+
" Invoice Amount : “+ strfmt(”%1”, parmLedgerJournalTrans.amount())+".";

CodeAccessPermission::revertAssert();
permission.assert();
if (_emailTo != “”)
{
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);
}
mailer.fromAddress(emailFrom);
mailer.tos().appendAddress(_emailTo);
mailer.subject(_subject);
mailer.htmlBody(_bodyText);
mailer.sendMail();
mailer.tos().clear();
_emailTo =" “;
}
CodeAccessPermission::revertAssert();
}
else
{
while select vendTrans where vendTrans.LastSettleVoucher == parmLedgerJournalTrans.Voucher
{
if (_invoice)
{
_invoice = _invoice + “, “+vendTrans.Invoice ;
_invoiceamt = _invoiceamt + “, “+strfmt(”%1”, abs(vendTrans.AmountMST));
_invoiceDate = _invoiceDate + " ,”+strfmt(”%1”,_invoiceDate);
}
else
{
_invoice = vendTrans.Invoice;
_invoiceamt = strfmt("%1", abs(vendTrans.AmountMST));
_invoiceDate = strfmt("%1",parmLedgerJournalTrans.TransDate);

}
}
_emailTo = vendtable::find(parmLedgerJournalTrans.AccountNum).Email;
_subject = “Payment Notification “;
_bodyText= “Dear " + parmLedgerJournalTrans.accountName()+” , “+“Following payment is credited to your account : " + " Invoice Number : " +strfmt(”%1”,_invoice)+” ; “+
" Invoice Date : " + strfmt(”%1”,_InvoiceDate) +" ; “+
" Invoice Amount : “+ strfmt(”%1”,_invoiceamt)+" . ";

CodeAccessPermission::revertAssert();
permission.assert();
if (_emailTo != “”)
{
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);
}
mailer.fromAddress(emailFrom);
mailer.tos().appendAddress(_emailTo);
mailer.subject(_subject);
mailer.htmlBody(_bodyText);
mailer.sendMail();
mailer.tos().clear();
_emailTo =" ";
}
CodeAccessPermission::revertAssert();

}
}
}

shall i use this code any where ? or i need to Write New ?

Hi ,

Your requirement is to trigger an email when invoice posting is done?

Thanks Reply Anitha .
yes .Path >> AP>>Purchase Order Details>> I am selecting One Purchase Order >> Posting Button >>Invoice >> It will Open Invoice Posting Form >> we will give Invoice Field (INV 001) and click on OK button .
in the purchase Order Form in Status >>it will show Invoiced .
when invoiced changed in status field that time mail should trigger with Invoice Number , Invoice Amount and invoice Date …
where i need to call the email method ? in the above code i changed but still i am getting

You can use the method “PostJournalPost” in the class PurchInvoiceJournalPost

thanks , i didn’t find PurchInvoiceJournalPost class in AX 2009 . ?

Ok. Since you have not mentioned the Ax version, I assumed it is AX2012.

I do not have an environment to check for Ax2009. Can you check if there are any posting classes for PurchInvoice ?