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)

Is it possible to print two unique SSRS reports in one clicked() method?

(0) ShareShare
ReportReport
Posted on by 2,007

I have been trying to override the clicked() method on a form in order to print two reports in succession. When I click the button, the behavior I get is that the first report (a custom BOL report) runs and then only when I close it does the second report (a quality certificate) run. I would like for both of them to run when I click the button.

Both of the reports have custom controllers. Here is the code in the clicked() method:

void clicked()
{
    MenuFunction        menufunction;
    MenuFunction        certMenuFunction;
    WMSOrderTrans       wmsOrderTrans;
    Args                args;
    ;

    menufunction = new MenuFunction(menuItemOutputStr(FSBillOfLading),MenuItemType::Output);
    args = new Args();
    args.parm(WMSShipment.shipmentId);
    menufunction.run(args);

    select firstOnly InventTransId from wmsOrderTrans
        where wmsOrderTrans.shipmentId == WMSShipment.shipmentId;

    if (wmsOrderTrans.getCertType() == OSCertType::Letterhead)
    {
        certMenuFunction = new MenuFunction(menuitemOutputStr(LetterheadCert),MenuItemType::Output);
        certMenuFunction.run(args);
    }
}

I am wondering if I need to nest one of the controller calls inside the other, since they use the same query and ranges. However, if I nest them, I may print them in the wrong order.

Any suggestions?

Brandt

 

*This post is locked for comments

I have the same question (0)
  • dolee Profile Picture
    11,279 on at

    Hi Brandt,

    I did something similar before. I needed to print different designs of the same report in one click.

    What I did was overriding the run method of the controller like below:

    public void run()

    {

       super();

       if ([condition is true])

       {

           this.parmReportName([another design]);

           super();

       }

    }

    This way the 2nd design will print without the need to close the first one. I think it would work for your cause if you substitute the second super(); call with another report.

    - For the order of the printouts, the 2nd report will *start* printing after the 1st one. However, if the first one takes awhile to print, then the 2nd report could come out first.

    - Also, since you are printing a different report, you will probably call .showDialog(false) in your code. It might get saved to sysLastValue such that when you try to print the 2nd report by itself, the dialog won't come up. To avoid this you can create a separate controller class for the 2nd report, specific for silent run.

    Kind regards,

    Dominic Lee

  • Brandt Fundak Profile Picture
    2,007 on at

    Dominic,

    Actually we want both reports to use the record currently selected in the form and so the dialog not appearing is actually the desired behavior.

    Both reports have a controller. I am assuming I just instantiate the second controller inside the overridden method of the first one?

    Brandt

  • dolee Profile Picture
    11,279 on at

    Yes, please try that. Remember to pass the print settings over besides the report parameters.

    Kind regards,

    Dominic Lee

  • Brandt Fundak Profile Picture
    2,007 on at

    Dominic,

    Two last questions.

    1. How do you pass the print settings to the second controller? I don't see a method in the SRSReportRunController to do that.

    2. The spec also wants similar logic applied to when an invoice is printed. However, one of the parent classes of SalesInvoiceController declares the run method final, so it cannot be overridden. Does it make more sense to put the logic in the runPrintMgmt() method of SalesInvoiceController or the outputReport() method? They want the second report to print per invoice, so maybe outputReport() makes the most sense, since it is the code that runs each printed invoice?

    Thanks for all of your advice, I really appreciate it.

    Brandt

  • dolee Profile Picture
    11,279 on at

    Hi Brandt,

    1. controller.parmReportContract().parmPrintSettings(this.parmReportContract().parmPrintSettings());

    where "controller" is the second report's controller.

    On the other hand, I just realize my method still would require user to "close" the first report viewer before the 2nd one would run. Sorry for the mis-information. (I thought it worked because the requirement I had was to print multiple copies to printer, not to screen).

    I'll try to see if I can find a way to get around it.

    Kind regards,

    Dominic Lee

  • dolee Profile Picture
    11,279 on at

    Hi Brandt,

    I found one work around (but not pretty) for printing to screen. Modify the SrsReportViewer form, call a custom method at the end of the form's run method.

    In the custom method, do something like:

    private void customMethod()

    {

        SecondReportController controllerNew;

        if (controller.parmReportName() == ssrsReportStr(firstReport,Report))

        {

               controllerNew = new SecondReportcontroller();

               ....

               ....

               controllerNew.startOperation();

        }

    }

    Note that this only applies when printing to screen. A combination of this work around and the original suggestion will be needed if you want consistent behavior. Check needs to be done on the printing destination such that the second report won't print twice.

    And on your question on SalesInvoiceController, with modification on SrsReportViewer form taking care of the Close-to-View-Second-Report problem, I think now you are free to trigger the second report anywhere after the first report. For example:

    - Override PostReportRun (remember to preserve the super() call).

    - Create Post event handler on an appropriate method.

    P.S. I picked 2 relatively simple reports (Vendor master and Customer master) to test the SrsReportViewer trick. Hopefully it'll work for you also.

    Kind regards,

    Dominic Lee

  • Brandt Fundak Profile Picture
    2,007 on at

    Dominic,

    I drew the same conclusions you did late in the day. I am currently trying to get the analyst assigned to this mod into a meeting to discuss options, as I think we should only be doing this when printing directly to the printer and not when printing to the screen. Modifying the SRSReportViewer form is something I don't think we want to do.

    I really do appreciate all of your help in this. I can handle the basics of report development fine, but most of my experience with AX has been in doing modifications in functionality and we have always subcontracted out the report work to our partners. Our analysts want these things to cook their breakfast for them in addition to all of the other things that software is actually supposed to do.

    Guess it's time to start digging into print management...

    Thanks again.

    Brandt

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
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans