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,325

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

  • Inkogo Profile Picture
    2 on at
    Print Report to Printer through X++ Code in DAX 2009
    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! ;)
  • Community Member Profile Picture
    on at
    Re: Print Report to Printer through X++ Code in DAX 2009

    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.

  • SarShalom Profile Picture
    20 on at
    Re: Print Report to Printer through X++ Code in DAX 2009

    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
    Re: Print Report to Printer through X++ Code in DAX 2009

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

  • haroonattari Profile Picture
    2,325 on at
    Re: Re: Print Report to Printer through X++ Code in DAX 2009

    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.

  • Rajdip Das Profile Picture
    3,333 on at
    Re: Print Report to Printer through X++ Code in DAX 2009

    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. :)

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics AX (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 100 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 48

#3
shanawaz davood basha Profile Picture

shanawaz davood basha 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans