Send Auto-Email when purchase order posting a product receipt
Today i am going to show you code how to send an auto-email through x++ code when the purchase order posting a product receipt
class DAL_PurchFormLetterClass_EventHandler
{
///
<summary>
///
///
</summary>
///
<param name="args"></param>
[PostHandlerFor(classStr(PurchFormLetter), methodStr(PurchFormLetter, run))]
public static void
PurchFormLetter_Post_run(XppPrePostArgs args)
{
PurchFormLetter PurchFormLetter =
args.getThis() as PurchFormLetter ;
VendPackingSlipJour vendPackingSlipJour;
PurchTable PurchTable = PurchFormLetter.purchTable();
if(PurchFormLetter.documentStatus() == DocumentStatus::PackingSlip
&&
!PurchFormLetter.proforma())
{
vendPackingSlipJour =
PurchFormLetter.parmJournalRecord();
this.sendMail_ProductReceipt(vendPackingSlipJour);
}
}
public void sendMail_ProductReceipt(VendPackingSlipJour _vendPackingSLipJour)
{
Set permSet;
FileName
filename,localfilename;
SRSPrintDestinationSettings printerSettings;
Array arrayFiles;
System.Byte[]
reportBytes = new System.Byte[0]();
SRSProxy srsProxy;
SRSReportRunService srsReportRunService = new SrsReportRunService();
Microsoft.Dynamics.AX.Framework.Reporting.Shared.ReportingService.ParameterValue[] parameterValueArray;
Map
reportParametersMap;
SRSReportExecutionInfo executionInfo = new SRSReportExecutionInfo();
int tryagain;
str email;
Notes content;
MenuFunction mf;
FormRun formrun;
Args _args;
EmailBase ToMailId;
PurchTable purchTableObj;
str
subjectPart,bodyMessage;
HcmWorkerName salesResponsible;
;
select purchTableObj where purchTableObj.PurchId == _vendPackingSLipJour.PurchId;
if(purchTableObj.DALWorkerSalesResponsible)
{
if(purchTableObj.DALWorkOrderNum)
{
bodyMessage = strFmt('The items ordered
vide work order number %3 is received
through product receipt number %1 dated
%2 .',_vendPackingSLipJour.PackingSlipId,_vendPackingSLipJour.DeliveryDate,purchTableObj.DALWorkOrderNum);
subjectPart = "work order
number -" + purchTableObj.DALWorkOrderNum;
}
else
{
if(purchTableObj.DALSalesId)
{
bodyMessage = strFmt('The items ordered
vide sales order number %3 is received
through product receipt number %1 dated
%2 .',_vendPackingSLipJour.PackingSlipId,_vendPackingSLipJour.DeliveryDate,purchTableObj.DALSalesId);
subjectPart = "Sales order
number -" + purchTableObj.DALSalesId;
}
}
ToMailId = DALParameterTable::getUserEmail(purchTableObj.DALWorkerSalesResponsible);
salesResponsible = HcmWorker::find(purchTableObj.DALWorkerSalesResponsible).name();
System.IO.Stream workbookStream = new System.IO.MemoryStream();
SysMailerSMTP mailer = new SysMailerSMTP();
SysMailerMessageBuilder builder = new SysMailerMessageBuilder();
SysEmailParameters parameters = SysEmailParameters::find();
if (parameters.SMTPRelayServerName)
{
mailer.SMTPRelayServer(parameters.SMTPRelayServerName,
parameters.SMTPPortNumber,
parameters.SMTPUserName,
SysEmailParameters::password(),
parameters.SMTPUseNTLM);
}
else
{
warning("@ApplicationFoundation:EmailProviderSMTPServerNotFound");
}
content ="";
content = content + strfmt("\n<p dir=ltr align=left><font size='2' face='arial'>Dear %1, </font></p> ",salesResponsible);
content = content + strfmt('\n<p dir=ltr
align=left>
</p>');
content = content + strfmt('\n<p dir=ltr
align=left>
</p>');
content = content + strfmt("\n<p dir=ltr align=left><font size='2' face='arial'> %1 </font></p> ",bodyMessage);
content = content + strfmt('\n<p dir=ltr
align=left></p>');
content = content + strfmt('\n<p dir=ltr
align=left></p>');
content = content + strfmt('\n<p dir=ltr align=left> </p>');
content = content + strfmt('\n<p dir=ltr
align=left> </p>');
content = content + strfmt('\n<p dir=ltr
align=left> </p>');
content = content + strfmt("\n<p
dir=ltr align=left><font size='2' face='arial'>Thanks &
Regards,</font></p> ");
content = content + strfmt("\n<p
dir=ltr align=left><font size='2' face='arial'> Procurement
Team</font></p> ");
content = content + strfmt('\n<p dir=ltr
align=left></p>');
content = content + strfmt('\n<p dir=ltr
align=left> </p>');
content = content + strfmt("\n<p
dir=ltr align=left> <B><font size='2' face='arial'>This email was
sent by an automated system. Please do not reply to this
message.</font></B></p> ");
sleep(5000); //Wait 5 seconds for network file write
tryagain = 0;
builder.setFrom(parameters.SMTPUserName);
builder.addTo(ToMailId);
builder.setSubject(strfmt("Items received
for %1",subjectPart));
builder.setBody(content); SysMailerFactory::getNonInteractiveMailer().sendNonInteractive(builder.getMessage());
}
}
}
Output:
}
Comments
Post a Comment