Writing a report to file, through code
I was working with another co-worker on a way to generate reports in AX as a PDF, and then Automatically email these out. One of the first things that needed to be done was call the report and save it to a file, without having user interaction.
Below is code that will call the SalesInvoice and generate it as a PDF file:
CustInvoiceJour InvJTbl;
SalesId Id;
ReportRun report;
RecordSortedList List = new RecordSortedList(62);
Id = "SO-0000123";
Select InvJTbl Where InvJTbl.SalesId == Id;
List.ins(InvJTbl);
report = new ReportRun(new Args(ReportStr(SalesInvoice)));
report.args().caller(null);
report.args().parmEnum(1);
report.args().parmEnumType(920);
report.args().object(List);
report.args().name("KeepSettings");
report.printJobSettings().setTarget(PrintMedium::File);
report.printJobSettings().format(PrintFormat::PDF);
report.printJobSettings().fileName("C:\\Temp\\Test.pdf");
report.prompt();
report.run();
This code can be expanded on from here. Hopefully someone can get some use out of this, as we did. To give a better idea, we used this to generate EI's or Electronic Invoices. This was done so that One invoice would exists, instead of having to maintain an Axapta Invoice, and then a Sepearate one for the HTML emailed version that some customers got.
All in all it worked out pretty good, there are some differences though that you have to deal with. The PDF may come out slightly different looking (ie: Company Logo) than what it looks like from within AX.
Find a job at: www.DynamicsAXJobs.com
Below is code that will call the SalesInvoice and generate it as a PDF file:
CustInvoiceJour InvJTbl;
SalesId Id;
ReportRun report;
RecordSortedList List = new RecordSortedList(62);
Id = "SO-0000123";
Select InvJTbl Where InvJTbl.SalesId == Id;
List.ins(InvJTbl);
report = new ReportRun(new Args(ReportStr(SalesInvoice)));
report.args().caller(null);
report.args().parmEnum(1);
report.args().parmEnumType(920);
report.args().object(List);
report.args().name("KeepSettings");
report.printJobSettings().setTarget(PrintMedium::File);
report.printJobSettings().format(PrintFormat::PDF);
report.printJobSettings().fileName("C:\\Temp\\Test.pdf");
report.prompt();
report.run();
This code can be expanded on from here. Hopefully someone can get some use out of this, as we did. To give a better idea, we used this to generate EI's or Electronic Invoices. This was done so that One invoice would exists, instead of having to maintain an Axapta Invoice, and then a Sepearate one for the HTML emailed version that some customers got.
All in all it worked out pretty good, there are some differences though that you have to deal with. The PDF may come out slightly different looking (ie: Company Logo) than what it looks like from within AX.
Find a job at: www.DynamicsAXJobs.com