Skip to main content

Notifications

Microsoft Dynamics AX forum
Unanswered

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

Posted on by 2,300

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.

  • Inkogo Profile Picture
    Inkogo 7 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
    Community Member Microsoft Employee 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
    SarShalom 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
    Community Member Microsoft Employee 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
    haroonattari 2,300 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
    Rajdip Das 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

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,451 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,353 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans