How to send Normal AX Reports as a PDF and User through Batch Process in Dynamics Ax 2009.
Hi friends,
Recently I got one requirements from my User, I.e. customer want to see ax reports in E-mail everyday once through batch process.
its just like send mail from batch process only, But we need to work on how to send normal report.
1) write the class with below methods mandatory.
2)Here am going to post logic for how to convert ax report to PDF and how to send the email to user only.
// Saved the reports into particular location
static void Job10(Args _args)
{
Args args;
ReportRun rr;
str reportName = "Custtable";
str myPath,pdfFileName;
;
args = new Args(reportName);
args.caller(rr);
rr = new reportRun(args);
rr.query().interactive(false);
rr.report().interactive(false);
rr.setTarget(printMedium::File);
rr.printJobSettings().setTarget(PrintMedium::File);
rr.printJobSettings().preferredTarget(PrintMedium::File);
rr.printJobSettings().format(PrintFormat::PDF);
rr.printJobSettings().warnIfFileExists(false);
rr.printJobSettings().suppressScalingMessage(true);
pdfFileName = @"C:\Users\Desktop\DateWise\3192014\Report1.pdf";
rr.printJobSettings().fileName(pdfFileName);
rr.init();
rr.run();
info("Report hasbeen saved");
}
void SaveReport()
{
Args args;
ReportRun rr;
str reportName = "OpenPurchOrderLine_Vendor";
str myPath;
int i;
;
i = 1;
args = new Args(reportName);
args.caller(rr);
rr = new reportRun(args);
rr.query().interactive(false);
rr.report().interactive(false);
rr.setTarget(printMedium::File);
rr.printJobSettings().setTarget(PrintMedium::File);
rr.printJobSettings().preferredTarget(PrintMedium::File);
rr.printJobSettings().format(PrintFormat::PDF);
rr.printJobSettings().warnIfFileExists(false);
rr.printJobSettings().suppressScalingMessage(true);
pdfFileName = @\\AXTESTDEV1\D$\Test\test.pdf; //@ is used for server\\ServerName\drive name$\Folder
rr.printJobSettings().fileName(pdfFileName);
rr.init();
rr.run();
info("Report has been saved");
}
//Used to sending emails to particular users
void EmailCheck()
{
//Set permissionSet2 = new Set(Types::Class);
InteropPermission permission = new InteropPermission(InteropKind::ComInterop);
;
CodeAccessPermission::revertAssert();
info("After code access in EmailCheck()");
permission.assert();
mailer = new SysMailer();
parameters = SysEmailParameters::find();
if (parameters.SMTPRelayServerName)
{
mailer.SMTPRelayServer(parameters.SMTPRelayServerName,
parameters.SMTPPortNumber,
parameters.SMTPUserName,
SysEmailParameters::password(),
parameters.NTLM);
info("if");
}
else
{
mailer.SMTPRelayServer(parameters.SMTPServerIPAddress, parameters.SMTPPortNumber,
parameters.SMTPUserName,
SysEmailParameters::password(),
parameters.NTLM);
info("else");
}
mailer.fromAddress('xyz@abc.com');
mailer.tos().appendAddress('abc@xyz.com');
mailer.tos().appendAddress('TEST@company.com');
mailer.htmlBody('Find the attachment.
<Br>\n NOTE:This is a System Generated Email. Please do not Reply.');
mailer.subject('Report Attached(Testing Mail)');
info(pdfFileName);
mailer.attachments().add("D:\\Test\\test.pdf");
mailer.sendMail();
CodeAccessPermission::revertAssert();
}
Next Configure this class into batch Job User Form.....
If any clarification or issues please comments to this..
Set query Range for Existing report in while running in class PrintMedium settings for Report in class
Method()
{
Args args;
ReportRun reportRun;
str reportName = "ReportNameTest";
str myPath;
int i;
TransDate td;
TransDate vd;
str rangeDate;
;
i = 1;
td = systemDateget();
args = new Args(reportName);
args.caller(reportRun);
reportRun = new reportRun(args);
reportRun.query().interactive(false);
reportRun.query().dataSourceTable(tablenum(TableNmae)).addRange(fieldNum(TableNmae,FeildNmae)).value(SysQuery::value(td));
reportRun.report().interactive(false);
reportRun.setTarget(printMedium::File);
reportRun.printJobSettings().setTarget(PrintMedium::File);
reportRun.printJobSettings().preferredTarget(PrintMedium::File);
reportRun.printJobSettings().format(PrintFormat::PDF);
reportRun.printJobSettings().warnIfFileExists(false);
reportRun.printJobSettings().suppressScalingMessage(true);
pdfFileName = @"\\AXTESTDEV1\D$\Demo\Test.pdf";
reportRun.printJobSettings().fileName(pdfFileName);
reportRun.init();
reportRun.run();
}
static void email(Args _args)
{
// For email notification
str messageBody;
NWH_XmlImpErrorFlag XmlImpErrorFlag;
InteropPermission permission = new InteropPermission(InteropKind::ComInterop);
SysMailer mailer;
str Body;
str ToAddress;
str FromAddress = "aslam.pasha@infotech.net";
str Subject = "Integration Alerts";
int x;
H_IntegrationParameters parameters;
Container id;
LedgerJournalTrans ljt;
date checkdate;
Real CheckDr , CheckCr ;
int i,j;
;
try
{
info("In the 'try' block. (j1)");
info("infolog!");
throw warning("test warning");
throw error("test error");
info("infolog!");
throw warning("test warning");
//throw Exception::Error;
}
catch
{
for (i=1; i<=infolog.line(); i++)
{
messageBody = ":" + infolog.text(i);
}
parameters = H_IntegrationParameters::find();
id = str2con(parameters.HSEmailId,",");
for(x=1 ; x <= conlen(id); x++ )
{
toaddress = strRem(conpeek(id,x)," ");
Body = strfmt("%1", messageBody) ;
CodeAccessPermission::revertAssert();
permission.assert();
mailer = new SysMailer();
// CodeAccessPermission::revertAssert();
mailer.quickSend(fromaddress,toaddress,subject,Body);
}
}
}
Hi friends,
Recently I got one requirements from my User, I.e. customer want to see ax reports in E-mail everyday once through batch process.
its just like send mail from batch process only, But we need to work on how to send normal report.
1) write the class with below methods mandatory.
2)Here am going to post logic for how to convert ax report to PDF and how to send the email to user only.
// Saved the reports into particular location
static void Job10(Args _args)
{
Args args;
ReportRun rr;
str reportName = "Custtable";
str myPath,pdfFileName;
;
args = new Args(reportName);
args.caller(rr);
rr = new reportRun(args);
rr.query().interactive(false);
rr.report().interactive(false);
rr.setTarget(printMedium::File);
rr.printJobSettings().setTarget(PrintMedium::File);
rr.printJobSettings().preferredTarget(PrintMedium::File);
rr.printJobSettings().format(PrintFormat::PDF);
rr.printJobSettings().warnIfFileExists(false);
rr.printJobSettings().suppressScalingMessage(true);
pdfFileName = @"C:\Users\Desktop\DateWise\3192014\Report1.pdf";
rr.printJobSettings().fileName(pdfFileName);
rr.init();
rr.run();
info("Report hasbeen saved");
}
void SaveReport()
{
Args args;
ReportRun rr;
str reportName = "OpenPurchOrderLine_Vendor";
str myPath;
int i;
;
i = 1;
args = new Args(reportName);
args.caller(rr);
rr = new reportRun(args);
rr.query().interactive(false);
rr.report().interactive(false);
rr.setTarget(printMedium::File);
rr.printJobSettings().setTarget(PrintMedium::File);
rr.printJobSettings().preferredTarget(PrintMedium::File);
rr.printJobSettings().format(PrintFormat::PDF);
rr.printJobSettings().warnIfFileExists(false);
rr.printJobSettings().suppressScalingMessage(true);
pdfFileName = @\\AXTESTDEV1\D$\Test\test.pdf; //@ is used for server\\ServerName\drive name$\Folder
rr.printJobSettings().fileName(pdfFileName);
rr.init();
rr.run();
info("Report has been saved");
}
//Used to sending emails to particular users
void EmailCheck()
{
//Set permissionSet2 = new Set(Types::Class);
InteropPermission permission = new InteropPermission(InteropKind::ComInterop);
;
CodeAccessPermission::revertAssert();
info("After code access in EmailCheck()");
permission.assert();
mailer = new SysMailer();
parameters = SysEmailParameters::find();
if (parameters.SMTPRelayServerName)
{
mailer.SMTPRelayServer(parameters.SMTPRelayServerName,
parameters.SMTPPortNumber,
parameters.SMTPUserName,
SysEmailParameters::password(),
parameters.NTLM);
info("if");
}
else
{
mailer.SMTPRelayServer(parameters.SMTPServerIPAddress, parameters.SMTPPortNumber,
parameters.SMTPUserName,
SysEmailParameters::password(),
parameters.NTLM);
info("else");
}
mailer.fromAddress('xyz@abc.com');
mailer.tos().appendAddress('abc@xyz.com');
mailer.tos().appendAddress('TEST@company.com');
mailer.htmlBody('Find the attachment.
<Br>\n NOTE:This is a System Generated Email. Please do not Reply.');
mailer.subject('Report Attached(Testing Mail)');
info(pdfFileName);
mailer.attachments().add("D:\\Test\\test.pdf");
mailer.sendMail();
CodeAccessPermission::revertAssert();
}
Next Configure this class into batch Job User Form.....
If any clarification or issues please comments to this..
Set query Range for Existing report in while running in class PrintMedium settings for Report in class
Method()
{
Args args;
ReportRun reportRun;
str reportName = "ReportNameTest";
str myPath;
int i;
TransDate td;
TransDate vd;
str rangeDate;
;
i = 1;
td = systemDateget();
args = new Args(reportName);
args.caller(reportRun);
reportRun = new reportRun(args);
reportRun.query().interactive(false);
reportRun.query().dataSourceTable(tablenum(TableNmae)).addRange(fieldNum(TableNmae,FeildNmae)).value(SysQuery::value(td));
reportRun.report().interactive(false);
reportRun.setTarget(printMedium::File);
reportRun.printJobSettings().setTarget(PrintMedium::File);
reportRun.printJobSettings().preferredTarget(PrintMedium::File);
reportRun.printJobSettings().format(PrintFormat::PDF);
reportRun.printJobSettings().warnIfFileExists(false);
reportRun.printJobSettings().suppressScalingMessage(true);
pdfFileName = @"\\AXTESTDEV1\D$\Demo\Test.pdf";
reportRun.printJobSettings().fileName(pdfFileName);
reportRun.init();
reportRun.run();
}
static void email(Args _args)
{
// For email notification
str messageBody;
NWH_XmlImpErrorFlag XmlImpErrorFlag;
InteropPermission permission = new InteropPermission(InteropKind::ComInterop);
SysMailer mailer;
str Body;
str ToAddress;
str FromAddress = "aslam.pasha@infotech.net";
str Subject = "Integration Alerts";
int x;
H_IntegrationParameters parameters;
Container id;
LedgerJournalTrans ljt;
date checkdate;
Real CheckDr , CheckCr ;
int i,j;
;
try
{
info("In the 'try' block. (j1)");
info("infolog!");
throw warning("test warning");
throw error("test error");
info("infolog!");
throw warning("test warning");
//throw Exception::Error;
}
catch
{
for (i=1; i<=infolog.line(); i++)
{
messageBody = ":" + infolog.text(i);
}
parameters = H_IntegrationParameters::find();
id = str2con(parameters.HSEmailId,",");
for(x=1 ; x <= conlen(id); x++ )
{
toaddress = strRem(conpeek(id,x)," ");
Body = strfmt("%1", messageBody) ;
CodeAccessPermission::revertAssert();
permission.assert();
mailer = new SysMailer();
// CodeAccessPermission::revertAssert();
mailer.quickSend(fromaddress,toaddress,subject,Body);
}
}
}
Here is Mr Benjamin contact Email details, 247officedept@gmail.com. / Or Whatsapp +1 989-394-3740 that helped me with loan of 90,000.00 Euros to startup my business and I'm very grateful,It was really hard on me here trying to make a way as a single mother things hasn't be easy with me but with the help of Mr Benjamin put smile on my face as i watch my business growing stronger and expanding as well.I know you may surprise why me putting things like this here but i really have to express my gratitude so anyone seeking for financial help or going through hardship with there business or want to startup business project can see to this and have hope of getting out of the hardship..Thank You.
ReplyDelete