web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Print Report to Printer through X++ Code in DAX 2009

(0) ShareShare
ReportReport
Posted on by 2,346

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.

*This post is locked for comments

I have the same question (0)
  • Rajdip Das Profile Picture
    3,333 on at

    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. :)
  • haroonattari Profile Picture
    2,346 on at

    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.

  • Community Member Profile Picture
    on at

    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();
    }

  • SarShalom Profile Picture
    20 on at

    Hello justin,

    I've tried your code and still the report preview is coming out instead of being printed to the printer.

  • Community Member Profile Picture
    on at

    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.

  • Inkogo Profile Picture
    2 on at
    What is missing is
     
    reportRun.printJobSettings().lockDestinationProperties(true)
     
    You don't have to wasting time with formLetter class.
    And recommended to call

    reportRun.init();
     
    as well before
     
    reportRun.run();
     
    Kind regards! ;)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Ali Zaidi Profile Picture

Ali Zaidi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans