Dynamics AX
  RSS Feed  LinkedIn  Twitter
Want to turn you're data into a true asset? Ready to break free from the report factory?
Ready to gain true insights that are action focused for truly data informed decisions?
Want to do all of this across mutliple companies, instances of Dynamics and your other investments?
Hillstar Business Intelligence is the answer then! (www.HillstarBI.com)

Hillstar Business Intelligence for Microsoft Dynamics AX and NAV on Mobile, Desktop, Tablet


Let us prove to you how we can take the complexity out of the schema and truly enable users to answer the needed questions to run your business! Visit Hillstar Business Solutions at: www.HillstarBI.com

Tuesday, January 24, 2006

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

12 Comments:

Anonymous Anonymous said...

Please help, I can't get the pdf-output file!
I copy/paste your code in a new job, add the declarations like:

custInvoiceJour InvJTbl;
SalesId salesId = "00014_036";
FileName filename = "c:\\temp\\output.pdf";
RecordSortedList List = new RecordSortedList(tableNum(CustInvoiceJour));
ReportRun report;
;
// your code comes here

What's wrong?

thanks

1:33 PM  
Anonymous Anonymous said...

This is all fine and dandy, but if I'm not mistaken the output is created on the file system of the client. So the question is how do you get this to work in a three tier environment where the clients have no access to the file system of the server? My guess is that you want the files created on the server rather than on different clients throughout the organization.

Regards,
Tobias

2:30 AM  
Anonymous home equity loans said...

home equity loans

11:42 PM  
Blogger Joe Berenguer said...

Hi Blogger!I like your blog! Keep up the
good work, you are providing a great resource on the Internet here!
If you have a moment, please take a look at my site:
job portal
It pretty much covers job portal related issues.
Best regards!

3:38 AM  
Blogger John said...

Couldn't get this to work as is - had to pass the PrintJobSettings in a SalesFormLetter_Invoice class like this (NOTE: when in doubt, set a break point and step into every call - you'll see in the .init() where it throws away all your settings and switches to PrintMedium::Screen... grrrr):
(add to Declarations)
SalesFormLetter_Invoice SalesFormLetter = new SalesFormLetter_Invoice(false);

(modify the .caller())
report.args().caller(SalesFormLetter);

(add this before you call .run())
SalesFormLetter.updatePrinterSettingsFormLetter(report.packPrintJobSettings());

Hope this helps all you frustrated x++ guys/gals out there!

4:24 PM  
Anonymous Anonymous said...

Great blog! Thank You ;)

2:07 AM  
Anonymous Anonymous said...

Thanks for the code! It's very helpfull!

2:12 AM  
Anonymous Dissertation Help said...

it's good to see this information in your post, i was looking the same but there was not any proper resource, thanx now i have the link which i was looking for my research.

7:27 AM  
Blogger Eduardo's Comments said...

http://axwonders.blogspot.com/2011/02/save-microsoft-dynamics-ax-2009-report.html

9:06 AM  
Blogger Eduardo's Comments said...

The code in this article did not work for me. The file was never saved into the location I was trying to save it to. However, the report was printed to the screen and from there I was able to save it manually.

This post helped me resolve the issue of saving the file as PDF into a local folder.

http://axwonders.blogspot.com/2011/02/save-microsoft-dynamics-ax-2009-report.html

I guess the main difference is that in the example shown in the link above is that it uses PrintJobSettings instead of the Report instances.

I hope this helps someone.

12:27 PM  
Anonymous Rob said...

You dont need to create a PrintJobSettings object to pass through the arguments, you can just set the one in the reportRun object. But you cannot call the init AFTER you create those settings as the init resets the printJobSettings to default. Like this (after you've initialized your ReportRun object):

oReportRun.setTarget(PrintMedium::File);
oReportRun.init(); oReportRun.printJobSettings().setTarget(PrintMedium::File);
oReportRun.printJobSettings().format(PrintFormat::PDF);
oReportRun.printJobSettings().fileName(fileName);
oReportRun.run();

4:07 PM  
Blogger Morgan Sundqvist said...

Hi,
I found a problem(Ax2009 SP 1 RU7) which lies in the salesFormLetterReport.loadPrintSettings method in the fetch method of the SalesInvoice report.

in the loadPrintSettings method there is a line if(!this.parmUseUserDefinedDestination)

If this is not set the printmanagement will revert back to Screen.

Best regards,

Morgan Sundqvist

2:43 AM  

Post a Comment

Links to this post:

Create a Link

<< Home


Copyright 2005-2011, J. Brandon George - All rights Reserved