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)

Running a Report from the selected record in a form

(0) ShareShare
ReportReport
Posted on by 211

I've created a Report that (hopefully) displays the information from one record in Table A and all related records in Table B.

I've also created a rudimentary Form that displays all entries from Table A.

How can I run my report so that it will contain the information from whatever row I have selected in my Form?

*This post is locked for comments

I have the same question (0)
  • Vilmos Kintera Profile Picture
    46,149 on at

    Try setting the datasource of the action/output menu item pointing to your report to the formdatasource of the record you intend to pass in.

  • Kempeth Profile Picture
    211 on at

    My output menu item does not have a datasource property...

  • Andrew Xu Profile Picture
    3,877 on at

    Kempeth,

    You need to pass that designated record of Table A to your report, so your report knows which record it's running against.

    You can find many examples in out of box AX, e.g. sales order packing slips. User can select a packing slip journal and print packing slip for that record.

  • Kempeth Profile Picture
    211 on at

    I've found this blog post: dynamicsaxinsight.wordpress.com/.../ax-2012-add-report-parameter-to-ssrs-query-report

    After the changes to the Query and Report I now have a button that displays the report.

    But... When I click the button my form selection is not passed to the report and I get this intermediate window that asks me for the report parameters.

  • Hichem.Chekebkeb Profile Picture
    3,371 on at

    A very quick search in Google gave me this : www.bhsolutions.com/.../how-to-launch-an-ssrs-report-from-ax-with-pre-loaded-parameters

  • Vilmos Kintera Profile Picture
    46,149 on at

    Look harder then, because the property is there, according to the documentation too. A menu item button is this control, which has the datasource flag:

    msdn.microsoft.com/.../formfunctionbuttoncontrol.aspx

    And this is all you need to populate for a query-based report.

    If you have a non-query-based report, then it is a different story, but you should have told that up front in your original post, by clearly defining requirements. In this case you need to pull the value from the caller in your report controller class.

  • Kempeth Profile Picture
    211 on at

    Ahh, you meant the property on the button - not the menu item. Yeah I've found that and set it. The problem is that this shows another windows where I need to manually set the parameters of the report instead of taking the selected record from my form...

    I did get a bit further by now using these two articles:

    [View:https://community.dynamics.com/ax/b/applicationdevelopmentblogdynamicsax/archive/2016/02/10/get-selected-records-in-a-grid-on-a-form-ax-x:750:50]

    [View:https://community.dynamics.com/ax/f/33/t/229395:750:50]

    I can now determine the selected record in X++ code and call the report from there. Unfortunately setting the parameter still doesn't work. I've had to change the code a bit because I don't have a Contract Class:

    void clicked()
    {
        MultiSelectionHelper    helper = MultiSelectionHelper::construct();
        NVCSCD1Report           reportRecord;
        
        SrsReportRunController          controller = new SrsReportRunController();
        SRSPrintDestinationSettings     settings;
        Args                            args = new Args();
        
        
        
        super();
        
        
        
        helper.parmDatasource(NVCSCD1Report_DS);
        reportRecord = helper.getFirst();
        if (reportRecord)
        {
            controller.parmReportName(ssrsReportStr(NvcScd1TestReportMain, Bericht));
            controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);
            controller.parmShowDialog(false);
            
            //salesInvoiceContract.parmRecordId(custInvoiceJour.RecId);
            //salesInvoiceContract.parmDocumentTitle(CustInvoiceJour.InvoiceId);
            //salesInvoiceContract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo());
    
            // (1) Try by passing args
            args.record(reportRecord);
            args.parmEnum(PrintCopyOriginal::Original);
            args.parmEnumType(enumNum(PrintCopyOriginal));
            //controller.parmReportContract().parmRdpContract(salesInvoiceContract);    
            controller.parmArgs(args);
    
            // (2) Try explicitly preventing loading from last value
            // controller.parmLoadFromSysLastValue(false);
            // Change print settings as needed
            settings = controller.parmReportContract().parmPrintSettings();
            settings.printMediumType(SRSPrintMediumType::Screen);
            //settings.fileFormat(SRSReportFileFormat::PDF);
            //settings.overwriteFile(true);
            //settings.fileName(@'C:\Temp\Invoice.pdf');
            controller.startOperation();
        }
    }

    I'll check Hichem's post next...

  • Hichem.Chekebkeb Profile Picture
    3,371 on at

    The code I provided has the same concept as yours but much cleaner.

  • Kempeth Profile Picture
    211 on at

    Thanks. But unfortunately it didn't work either.

    So I've tried your sample from bhsolutions and it threw an error at "contract.parmField(dataTable.dataField);". Apparently my DataContract was never set. So I handled that and created a new instance. Now the report gets shown directly but it still displays all records in the table...

  • Hichem.Chekebkeb Profile Picture
    3,371 on at

    If you can screenshot your code, it would help us better understand your issue, check your joins in the query also.

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
Liquid error: parsing "/globalsearch/?q=how+to+hack++in+roblox+train+to+fight" - Nested quantifier +.