I am trying to print report through code in Microsoft Dynamics AX. The code is running successfully but instead of sending the report to default printer the default print preview is showing. The code is as under:
void clicked()
{
Args args;
ReportRun reportRun;
CustConfirmJour custConfirmJour;
RecordSortedList list = new RecordSortedList(55);
SELECT firstonly custConfirmJour order by ConfirmID desc where custConfirmJour.SalesId == salesTable.SalesId ;
list.ins(custConfirmJour);
args = new Args(ReportStr(SalesConfirm));
args.designName("Standard");
reportRun = new ReportRun(args);
reportRun.args().caller(null);
reportRun.args().parmEnum(1);
reportRun.args().parmEnumType(920);
reportRun.args().object(List);
reportRun.args().name("KeepSettings");
reportRun.printJobSettings().setTarget(PrintMedium::Printer);
reportRun.run();
}
Any help will be highly appreciated.
I am working on a similar issue. To suppress the printer dialog, in the AOT, I set the interactive property on the report to “NO”. For my purposes I also set the Query interactive property to “NO”. my report has no user interaction at all.
Hello justin,
I've tried your code and still the report preview is coming out instead of being printed to the printer.
Normally what you're trying to do would work ok. The sales documents though work a little differently (Confirmations, Packing Slips, Invoices, etc). Since these reports normally will print during the posting process associated with it, the printer settings are pulled from the associated SalesFormLetter class, not from the print settings given to the reportRun object.
The way around it is easy enough. In your ReportRun args, give it a "fake" caller that's a SalesFormLetter_Confirm class, and put your printer settings into the SalesFormLetter class so it'll get unpacked in the report. The SalesFormLetter doesn't have to post anything, it just needs to contain the proper printer settings. So, something like this:
static void Job7(Args _args)
{
Args args;
ReportRun reportRun;
//Declare SalesFormLetter and PrintJobSettings objects
SalesFormLetter salesFormLetter;
PrintJobSettings printJobSettings;
CustConfirmJour custConfirmJour;
RecordSortedList list = new RecordSortedList(55);
;
SELECT firstonly custConfirmJour order by ConfirmID desc where custConfirmJour.SalesId == salesTable.SalesId ;
list.ins(custConfirmJour);
args = new Args(ReportStr(SalesConfirm));
args.designName("Standard");
//Create the SalesFormLetter_Confirm caller and set the printer settings
printJobSettings = new PrintJobSettings();
printJobSettings.setTarget(PrintMedium::Printer);
printJobSettings.preferredTarget(PrintMedium::Printer);
salesFormLetter = new SalesFormLetter_Confirm(false);
//Don't forget to pack the printJobSettings
salesFormLetter.updatePrinterSettingsFormLetter(printJobSettings.packPrintJobSettings());
//You can set the args parameters before you create the ReportRun object
args.caller(salesFormletter);
//***NOTE: if possible, don't use set values, use the enumnum() function and Enum::Value.
args.parmEnum(PrintCopyOriginal::Original);
args.parmEnumType(enumnum(PrintCopyOriginal));
args.object(list);
reportRun = new ReportRun(args);
reportRun.init();
reportRun.run();
}
Thanks Mr. Das for your reply. I changed my code as per your suggestion but still the report preview is coming out instead of report being printed directly to printer. Please note that the printer is also selected as default on which I need the report.
Hi, You can try the fllowing code instead of "reportRun.printJobSettings().setTarget(PrintMedium::Printer);". You have to modify your code to some extends for applying my code. 1st confirm that your printable printer set as default printer before run the report. printJobSettings = run.PrintJobSettings(); printJobSettings.SetTarget(PrintMedium::Printer);
Note: printJobSettings class also provide some information, please go-through this class when you get free. :)Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,451 Super User 2024 Season 2
Martin Dráb 228,353 Most Valuable Professional
nmaenpaa 101,148