I am trying to print sales confirmation report on a button click which I have added on Sales Order Detail form in Microsoft Dynamics AX 2009. On click event of that button, I have written following code:
void clicked()
{
Args args;
ReportRun reportRun;
SalesFormLetter salesFormLetter;
PrintJobSettings printJobSettings;
CustConfirmJour custConfirmJour;
RecordSortedList list = new RecordSortedList(55);
SalesTable s开发者_开发技巧alesTableUpdate;
;
SELECT firstonly custConfirmJour order by ConfirmID desc where custConfirmJour.SalesId == salesTable.SalesId ;
list.ins(custConfirmJour);
args = new Args(ReportStr(SalesConfirm));
printJobSettings = new PrintJobSettings();
printJobSettings.SetTarget(PrintMedium::Printer);
printJobSettings.suppressScalingMessage(true);
salesFormLetter = new SalesFormLetter_Confirm(true);
salesFormLetter.updatePrinterSettingsFormLetter(printJobSettings.packPrintJobSettings());
args.designName("Standard");
args.caller(salesFormletter);
args.parmEnum(PrintCopyOriginal::Original);
args.parmEnumType(enumnum(PrintCopyOriginal));
args.object(list);
reportRun = new ReportRun(args);
reportRun.setTarget(PrintMedium::Printer);
reportRun.init();
reportRun.run();
}
The code is running fine except on problem that instead of sending the report directly on printer, print preview is coming.
I will be very greateful if anyone of you could let me know what is wrong with this code.
Rgds
Haroon
Since you're not sending in an reference to any printer, it would have to use the default printer, which might very well be Microsoft XPS or some display capable printer.
I had to send in the printersetting to the report (SalesInvoice) and add some code to sniff out any sent printersetting. Otherwise, the report will use whatever printersetting that applies to that type of report. Getting that to work enabled me to pass in various printersettings, like Email, PDF, etc, etc... :-)
If you do not know the device that the user has set up as the default printer then it will always print to the default printer. If your default settings are to print to screen (even though you selected Print Medium::Printer) it will still go to screen. I would think that you should select PrintMedium::Screen and have it always go to screen so that the user can select a printer, otherwise they may not know where the report printed (I have some users that have odd choices as their default printer, which may be across the building).
try this:
public void run()
{
Args args;
ReportRun report;
str printer;
PrintJobSettings pjs;
;
args = new Args(reportstr("PwC_ExciseInvoice_Sales"));
counter = 1;
pjs = new printJobSettings();
while(counter <= maxReports)
{
args.parm(int2str(counter));
args.record(custInvoiceJour);
report = new ReportRun(args);
pjs.setTarget(PrintMedium::Printer);
report.setTarget(PrintMedium::Printer);
report.init();
report.run();
counter++;
}
}
Through this code, I am calling a report Thrice (variable maxReports), everytime it is going directly to the printer.
精彩评论